0

我想我只是在这里遗漏了一些东西。

我正在尝试使用我的应用程序设置https://github.com/nxtbgthng/OAuth2Client

我不明白我必须如何将 oauth 令牌传递给图书馆。

我打电话:

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

然后我成功获得了一个令牌:

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

我如何将令牌传递给图书馆?!

4

2 回答 2

1

事实证明一个人必须打电话:

 [[NXOAuth2AccountStore sharedStore] handleRedirectURL:url];

在:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
于 2014-01-31T14:31:45.027 回答
1

您需要使用 NXOAuth2Request 来使用您的 OAuthToken 来调用请求。他们的 github 页面中的示例代码如下。Token 由 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
           }];
于 2014-01-30T20:13:16.707 回答