2011-03-28 37 views

回答

0

GTM OAuth更新,但GData API也通過setAuthorizer方法支持此功能。我沒有注意到,直到我深入瞭解源代碼。

//save to keychain 
- (void)viewController:(GDataOAuthViewControllerTouch *)viewController 
     finishedWithAuth:(GDataOAuthAuthentication *)auth 
       error:(NSError *)error { 
if (error != nil) { 
     // Authentication failed 

    } else { 
     [[self youTubeService] setAuthorizer:auth]; 
    } 
} 

//check if authorized: 
- (BOOL)isAuthorized 
{ 
    GDataOAuthAuthentication * auth = [GDataOAuthViewControllerTouch authForGoogleFromKeychainForName:kAppServiceName]; 
    BOOL isSignedIn = [auth canAuthorize]; // returns NO if auth cannot authorize requests 
    if(isSignedIn) [[self youTubeService] setAuthorizer:auth]; 
    return isSignedIn; 
} 
0

如果您使用的是GTM Oauth庫(http://code.google.com/p/gtm-oauth/),則它們提供了一種通過服務名稱在鑰匙串中存儲訪問令牌信息的方法(例如「YouTubeAPI 「 或者其他的東西)。

此外,如果您使用原始用戶名/密碼,我肯定會將詳細信息存儲在鑰匙串中。科幻Hi-Fi有一個不錯的,易於使用的圖書館,我曾經使用 - http://github.com/ldandersen/scifihifi-iphone

+0

我使用的是http://code.google.com/p/gdata-objectivec-client上的內容。 GTM看起來好像可以和它一起工作。我會試一試,謝謝。 – akaru 2011-03-29 04:08:09

+0

沒問題,讓我知道結果如何。 – 2011-03-31 18:53:10

相關問題