0

アプリケーションでGoogle緯度操作を行うためにGoogle APIを使用しています。資格情報を使用してユーザーを認証するまで完了しました。今、最初のリクエストから生成されたautherization_codeを使用してaccesstokenを生成しようとしています。しかし、didReceiveData 関数のエラーとして、invalid_request を介しています。私の問題を解決するために私に提案してください。Oauth リクエストのフォーマットは以下のようなものを想定しています。

POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded

code=4/v6xr77ewYqhvHSyW6UJ1w7jKwAzu&
client_id=8819981768.apps.googleusercontent.com&
client_secret={client_secret}&
redirect_uri=https://oauth2-login-demo.appspot.com/code&
grant_type=authorization_code

上記のサービスcalllを実行するための私のiosコードは次のとおりです

   NSString * urlString = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/token?code=%@&client_id=363756608022.apps.googleusercontent.com&client_secret=dury2bxloSVQ1sdJjg9MKO9s&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code",[userDefaults valueForKey:@"accessTokenResponse"]];    
     NSURL * url = [NSURL URLWithString:urlString];

    NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url];
    [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPMethod:@"POST"];
    NSLog(@"sendng req : %@",request);
    NSURLConnection * connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
    [connection start];
4

1 に答える 1

0

asihttpheader を使用してヘッダー要求を形成します。[request setpostvalue" forkey :].これは私の問題を解決しました

于 2012-10-04T13:37:51.563 に答える