首页 > 解决方案 > OAuthSwift 没有成员“accessTokenBasicAuthentification”

问题描述

我正在尝试使用 OAuthSwift 库为使用其 Twitch 帐户登录的用户获取授权令牌。我正在使用示例代码,但我认为 Swift 5 存在问题。我使用的是 XCode 版本 10.3 (10G8):

    // create an instance and retain it
    oauthswift = OAuth2Swift(
        consumerKey:    "***",
        consumerSecret: "***",
        authorizeUrl: "https://id.twitch.tv/oauth2/validate",
        responseType: "code"
    )
    oauthswift.accessTokenBasicAuthentification = true

    //let codeVerifier = base64url("abcd...")
    //let codeChallenge = codeChallenge(for: codeVerifier)

    let handle = oauthswift.authorize(
        withCallbackURL: URL(string: "localhost")!,
        scope: "", state:"TWITCH") { result in
            switch result {
            case .success(let (credential, response, parameters)):
                print(credential.oauthToken)
            // Do your request
            case .failure(let error):
                print(error.localizedDescription)
            }
    }
} 

我在网上遇到了一个错误oauthswift.accessTokenBasicAuthentification = true

Value of type 'OAuthSwift?' has no member 'accessTokenBasicAuthentification'

然后我得到一个错误let handle =

Value of type 'OAuthSwift?' has no member 'authorize'

任何帮助将不胜感激。

谢谢!

编辑:可能是 Cocoapods 的问题。我不能pod 'OAuthSwift', '~> 2.0.0', says it can't find that version. Just installing using pod 'OAuthSwift'没有版本号只安装v1.3.0

编辑2:

知道了!感谢 Kiril,我能够将库更新到 v2(我使用 pod install 而不是 pod update)。然后,一旦库更新,我必须使用添加let初始化程序。更新代码:

// create an instance and retain it
        let oauthswift = OAuth2Swift(
            consumerKey:    "***",
            consumerSecret: "***",
            authorizeUrl: "https://id.twitch.tv/oauth2/validate",
            responseType: "code"
        )

        self.oauthswift = oauthswift
        oauthswift.accessTokenBasicAuthentification = true

标签: swiftoauth-2.0alamofiretwitch

解决方案


推荐阅读