gpt4 book ai didi

ios - oAuth2Client 如何将 token 传递给图书馆

转载 作者:行者123 更新时间:2023-11-28 22:16:43 26 4
gpt4 key购买 nike

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

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

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

我打电话:

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

然后我成功地获得了一个 token :

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

如何将 token 传递给图书馆?!

最佳答案

您需要使用 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
}];

关于ios - oAuth2Client 如何将 token 传递给图书馆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21465504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com