Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios RedditAPI返回401(使用OAuthSwift)_Ios_Swift_Oauth 2.0_Authorization_Reddit - Fatal编程技术网

Ios RedditAPI返回401(使用OAuthSwift)

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",

因此,我正在尝试让我的示例reddit应用程序与OAuthSwift一起工作

我从reddit那里得到了
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

你就完了