Ios RedditAPI返回401(使用OAuthSwift)
因此,我正在尝试让我的示例reddit应用程序与OAuthSwift一起工作 我从reddit那里得到了Ios RedditAPI返回401(使用OAuthSwift),ios,swift,oauth-2.0,authorization,reddit,Ios,Swift,Oauth 2.0,Authorization,Reddit,因此,我正在尝试让我的示例reddit应用程序与OAuthSwift一起工作 我从reddit那里得到了401和未经授权的 oauthswift = OAuth2Swift( consumerKey: "reddit_Client_id", consumerSecret: "", authorizeUrl: "https://www.reddit.com/api/v1/authorize",
401
和未经授权的
oauthswift = OAuth2Swift(
consumerKey: "reddit_Client_id",
consumerSecret: "",
authorizeUrl: "https://www.reddit.com/api/v1/authorize",
accessTokenUrl: "https://www.reddit.com/api/v1/access_token",
responseType: "code"
)
guard let rwURL = URL(string: "redditTestApp://oauth-callback") else { return }
handle = oauthswift!.authorize(
withCallbackURL: rwURL,
scope: "identity read", state:"reddit") { result in
switch result {
case .success(let (credential, response, parameters)):
print(credential.oauthToken)
// Do your request
case .failure(let error):
print(error.description)
}
}
我有点迷恋我在这里错过的东西。我想我已经传递了所有的参数,不确定还有什么原因可以得到
未经授权的响应。所以把它留在这里,以防万一将来有人需要帮助
问题在于,在检索访问令牌reddit期间,它需要一个带有http basic auth的授权头
OAuthSwift库提供了一种简单的方法,您只需添加
oauthswift?.accessTokenBasicAuthentification=true
你已经完成了。所以把它留在这里,以防万一将来有人需要帮助
问题在于,在检索访问令牌reddit期间,它需要一个带有http basic auth的授权头
OAuthSwift库提供了一种简单的方法,您只需添加
oauthswift?.accessTokenBasicAuthentification=true
你就完了