因此,我目前正在尝试通过使用OAuthSwift插件来获得Twitter工作的授权,我尝试使IT与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)")
}
)
我希望有人能够告诉我我在这里做错了什么,因为我似乎无法弄清楚。
问题最终是我设置了错误的URL方案。它包含一个不允许的_
。
在我的情况下,我没有在Twitter开发网站上设置该应用的回调URL -https://developer.twitter.twitter.com/en/apps