【发布时间】:2018-01-16 06:36:30
【问题描述】:
如何在 oauth swift lib 上传递令牌和令牌秘密
我在 lib 的 git 文档中找到了以下代码
// create an instance and retain it
let oauthswift = OAuth1Swift(
consumerKey: "********",
consumerSecret: "********"
)
// do your HTTP request without authorize
oauthswift.client.get("https://api.example.com/foo/bar",
success: { response in
//....
},
failure: { error in
//...
}
)
但是除了 consumerKey 和 consumerSecret 我还有 token 和 TokenSecret。所以我可以在 oAuthSwift 库中传递它。
我尝试了以下代码
let oauthswift = OAuth1Swift(
consumerKey:"102xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
consumerSecret:"5xxxxxxxxxxxxxxxxxxxxxxxxxxx",
token:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
tokenSeceret:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
但它给出错误“无法使用参数列表调用类型'OAuth1Swift'的初始化程序” 此库中有另一个可用的初始化程序,如下所示
// create an instance and retain it
oauthswift = OAuth1Swift(
consumerKey: "********",
consumerSecret: "********",
requestTokenUrl: "https://api.twitter.com/oauth/request_token",
authorizeUrl: "https://api.twitter.com/oauth/authorize",
accessTokenUrl: "https://api.twitter.com/oauth/access_token"
)
// authorize
let handle = oauthswift.authorize(
withCallbackURL: URL(string: "oauth-swift://oauth-callback/twitter")!,
success: { credential, response, parameters in
print(credential.oauthToken)
print(credential.oauthTokenSecret)
print(parameters["user_id"])
// Do your request
},
failure: { error in
print(error.localizedDescription)
}
)
但是我们没有这样的链接来获取令牌,而是我们使用已经创建的令牌和秘密
【问题讨论】:
标签: ios oauth swift4 oauth-1.0a