swift - 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
解决方案
推荐阅读
- wordpress - 有什么方法可以在 WordPress 设置的管理面板上显示具有特定类别的帖子列表?
- python - 具体何时删除功能范围(框架)?
- javascript - 如何使用javascript从驱动器中读取文件?
- c# - 正在下载的文件的文件大小太大
- domino-appdev-pack - 字段以单引号开头时的 DQL 查询格式
- java - Jackson:JsonBackReference - 无限递归问题
- php - Postgres pg_dump 显示空文件
- javascript - 使用多部分数据获取请求在 Firefox 中失败,但在 Safari 中失败
- java - 如何在 Firestore 中保存时间戳?
- json - PayPal 快递结帐 JSON 格式错误