2012-06-07 2 views
2

iPhone 응용 프로그램에서 Oauth 2.0을 사용하여 Google+ API에 액세스하려고합니다. 이 목적을 위해 OauthConsumer 라이브러리를 사용하고 있습니다. 승인되지 않은 request_token과 인증 코드가 있지만 인증 코드를 사용하여 access_token에 대한 request_token을 교환 할 수 없습니다. "invalid_request"로 오류가 발생했습니다. 아래는 코드 스 니펫입니다. 매개 변수가 잘못되었거나 누락 되었습니까?iPhone 응용 프로그램에서 Oauth 2.0을 통해 google +에 대한 액세스 토큰을 얻을 수 없습니다.

코드 :

-(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:)]; 
} 

답변

1

가 참고 - 내가 목표 - C에 익숙하지 해요,하지만 희망의 OAuth에 대한 약간의 지식이 당신이 알아내는 데 도움이됩니다. "오전 :

"승인 된 요청 토큰 "의 OAuth 1.0에 사용되는 는"인증 코드 "나는 OauthConsumer OAuth를 2.0

당신은 질문

을 지원한다는 아무것도 보이지 않아요

의 OAuth 2.0에서 사용되는 내가 틀린 일을하거나 매개 변수를 빠뜨린거야? "

OAuth 2.0의 액세스 토큰에 대한 인증 코드를 교환해야하는 클라이언트 비밀번호가 누락되었다고 생각합니다. 액세스 토큰에 대한 인증 코드를 교환하기 위해 제공해야 할 사항에 대한 자세한 내용은 Google OAuth 2.0 documentation을 참조하십시오.

당신은 Mac 용 구글 도구 상자 확인 할 수 있습니다 - OAuth를 2 개 컨트롤러 :

http://code.google.com/p/gtm-oauth2/wiki/Introduction

+0

안녕 라이언, 답장을 보내 주셔서 감사합니다. 내가 제안한대로 OAMutableURLRequest의 client_id 및 client_secret 매개 변수를 설정하고 access_token을 성공적으로 가져 왔습니다. –

관련 문제