iPhoneアプリケーションでOauth2.0を使用してGoogle+APIにアクセスしようとしています。この目的のために、私はOauthConsumerライブラリを使用しています。許可されていないrequest_tokenと認証コードを取得しましたが、認証コードを使用してそのrequest_tokenをaccess_tokenと交換できませんでした。「invalid_request」としてエラーが発生します。以下はコードスニペットです、私は何か間違ったことをしているのですか、それともパラメータがありませんか?
コード:
-(void)getAccessTokenWithAuthorizationCode:(NSString *)code
{
NSURL *accessTokenURL = [NSURL URLWithString:@"https://accounts.google.com/o/oauth2/token"];
OAMutableURLRequest *accessRequest = [[OAMutableURLRequest alloc] initWithURL:accessTokenURL
consumer:consumer
token:requestToken
realm:nil // our service provider doesn't specify a realm
signatureProvider:nil]; // use the default method, HMAC-SHA1
[accessRequest setHTTPMethod:@"POST"];
OARequestParameter *authCode = [[OARequestParameter alloc] initWithName:@"code" value:code];
OARequestParameter *redirectURI = [[OARequestParameter alloc] initWithName:@"redirect_uri" value:kRedirectURI];
OARequestParameter *granType = [[OARequestParameter alloc] initWithName:@"grant_type" value:@"authorization_code"];
[accessRequest setParameters:[NSArray arrayWithObjects:authCode, redirectURI, granType, nil]];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:accessRequest
delegate:self
didFinishSelector:@selector(accessTokenTicket:didFinishWithData:)
didFailSelector:@selector(accessTokenTicket:didFailWithError:)];
}