我正在尝试使用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安装而不是pod更新)。然后,一旦库更新,我就不得不使用添加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