【发布时间】:2017-07-23 20:14:55
【问题描述】:
因此,我目前正在尝试通过使用OAuthSwift 插件来获得 twitter 工作的授权,我试图让它与 OAuth1 和 OAuth2 一起工作,但都失败了,并且出现了不同的错误/问题。
所以对于 OAuth2 我得到了这个响应
哇!
此页面没有请求令牌。这是我们要求使用您的 Twitter 帐户的应用程序所需的特殊密钥。请返回将您发送到此处的站点或应用程序,然后重试;这可能只是一个错误。
我正在为此使用以下代码
let oauthswift = OAuth2Swift(
consumerKey: Twitter.consumerKey,
consumerSecret: Twitter.consumerSecret,
authorizeUrl: Twitter.authorizeURL,
accessTokenUrl: Twitter.accessTokenURL,
responseType: Twitter.responseType!)
let state = generateState(withLength: 20)
oauthswift.authorize(
withCallbackURL: "https://oauthswift.herokuapp.com/callback/twitter",
scope: "",
state: state,
success: { credential, response, parameters in
print("logged in with \(credential), with response \(response) and parameters \(parameters)")
},
failure: { error in
print("error occured \(error.localizedDescription)")
}
)
然后我继续使用 OAuth1,这给了我错误
Desktop applications only support the auth_callback value 'oob' 虽然我显然是在尝试从 iOS 应用程序中执行此操作。
我这里使用的代码如下
let oauthTwitter = OAuth1Swift(
consumerKey: "myKey",
consumerSecret: "mySecret",
requestTokenUrl: "https://api.twitter.com/oauth/request_token",
authorizeUrl: "https://api.twitter.com/oauth/authorize",
accessTokenUrl: "https://api.twitter.com/oauth/access_token")
oauthswift.authorize(
withCallbackURL: "https://oauthswift.herokuapp.com/callback/twitter",
scope: "",
state: state,
success: { credential, response, parameters in
print("logged in with \(credential), with response \(response) and parameters \(parameters)")
},
failure: { error in
print("error occured \(error.localizedDescription)")
}
)
我希望有人能够告诉我我在这里做错了什么,因为我似乎无法弄清楚。
【问题讨论】:
-
对于 OAuth1 错误?你在 Twitter 控制台中正确设置了回调 url 吗?
-
是的,问题最终导致我的 url 方案格式错误,其中包含
_,这是不允许的
标签: ios swift twitter oauth oauth-2.0