2014-01-30 58 views
0

我想我只是在這裏失去了一些東西。oAuth2Client你如何將令牌傳遞給庫

我試圖用我的應用程序設置https://github.com/nxtbgthng/OAuth2Client

我不明白我是如何將oauth標記傳遞給庫的。

我打電話:

[[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:@"myFancyService"]; 

然後我順利拿到令牌:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication annotation:(id)annotation; 

我如何通過令牌上的圖書館?

回答

1

原來一個人打電話:

[[NXOAuth2AccountStore sharedStore] handleRedirectURL:url]; 

在:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation; 
1

您需要使用NXOAuth2Request來使用您的OAuthToken來調用請求。下面是他們的github頁面中的示例代碼。令牌由NXOAuth2Account類包裝,該類又被包裝在NXOAuth2AccountStore單例中。

[[NXOAuth2AccountStore sharedStore] accounts] 

將返回一個帳戶數組。

然後,您可以使用您的帳戶作爲參數在以下方法中進行經過驗證的API調用。

[NXOAuth2Request performMethod:@"GET" 
       onResource:[NSURL URLWithString:@"https://...your service URL..."] 
      usingParameters:nil 
       withAccount:anAccount 
     sendProgressHandler:^(unsigned long long bytesSend, unsigned long long bytesTotal) { // e.g., update a progress indicator } 
      responseHandler:^(NSURLResponse *response, NSData *responseData, NSError *error){ 
       // Process the response 
      }]; 
+0

我檢查[NXOAuth2AccountStore sharedStore]帳戶。但是此時並未創建帳戶。它首先需要用AccessToken進行初始化。我有訪問令牌,但我現在沒有如何將它傳遞到庫,以便創建一個帳戶:( – 1b0t

+0

我有令牌作爲NSString。我的問題是,我不知道如何由於NXOAuthAccount的init方法是私有的,因此從令牌創建帳戶。 – 1b0t