2012-12-27 2 views
0

많은 검색 작업을 수행했지만 ASIHttpRequest 및 Youtube API에 대한 이해할 수있는 자습서를 찾을 수 없습니다. 나는 또한 Stackoverflow 및 기타 포럼에 많은 질문을하지만 아무도 도움이 될 수 있습니다. YouTube에서 좋아하는 비디오 목록을 얻으려고합니다. 나는 성공에 서명하고 accesstoken을 얻었다.ASIHTTPRequest 인증에 오류가 필요했습니다.

#define CONNECTION_GET_FAVORITE_LIST @"https://gdata.youtube.com/feeds/api/users/default/favorites" 

- (void) getFavoriteList{ 


    NSURL *url = [NSURL URLWithString:CONNECTION_GET_FAVORITE_LIST]; 
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url]; 
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 
    [request addRequestHeader:@"Authorization" value:[@" Bearer " stringByAppendingString:<accesstoken goes here>]; 
    request 
    [request startAsynchronous]; 
    [request setCompletionBlock:^{ 
     NSString* respondMessage = [request responseString]; 
     NSLog(@"Respond complete with message: %@",respondMessage); 
    }]; 
    [request setFailedBlock:^{ 
     NSString* respondMessage = [request error]; 
     NSLog(@"Respond failed with message: %@",respondMessage); 
    }]; 
    [request release]; 
} 

UPDATE : 난 항상 오류가 반환 키 인증하지만 유튜브와 요청 헤더로 설정 : 내 코드 여기

Respond failed with message: Error Domain=ASIHTTPRequestErrorDomain Code=3 "Authentication needed" UserInfo=0x933b980 {NSLocalizedDescription=Authentication needed}

이다 내가 GET 방식을 사용에 accesstoken을 설정하려고하면 같은 링크 : https://gdata.youtube.com/feeds/api/users/default/favorites?v=2&access_token=<accesstoken>은, 유튜브는 오류가 발생 :

Token invalid - AuthSub token has wrong scope

Error 401

제발 날이 문제를 해결하는 데 도움이됩니다. 고마워요

+0

토큰이 유효한지 확인하기 위해 https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2#OAuth2_Calling_a_Google_API에서 언급 한 것처럼 curl을 사용하여 명령 줄에서 동일한 요청을 테스트 해 보았습니까? – shawnwall

답변

1

Fristly ASIHTTPRequest 사용 AFNetworking을 사용하지 마십시오. 하지만 여기에는 아무도 필요하지 않습니다.

이제 을 요청하려면 authentication and authorization에서 gdata까지 youtube으로 요청해야합니다.

편집 : gtm-oauth2 링크를 참조하십시오.

GData Youtube API Documenttaion 링크를 참조하십시오.

관련 문제