I am attempting to use OAuth 1 with the Twitter API using OAuthSwift. I have completed all of the setup steps while building successfully throughout, but on the last step I am getting an error. When I implement the following code, I get an error saying “The operations cannot be completed. (OAuthSwiftError error -10)”. I am thinking it might have something to do with the callback URL but it is very unclear and there isn’t much documentation on this error. Or maybe there is something wrong with my key or secret? I have copied them directly from the Twitter dev site.
let oauthswift = OAuth1Swift(
consumerKey: CONSUMER_KEY,
consumerSecret: CONSUMER_SECRET,
requestTokenUrl: "https://api.twitter.com/oauth/request_token",
authorizeUrl: "https://api.twitter.com/oauth/authorize",
accessTokenUrl: "https://api.twitter.com/oauth/access_token"
)
let _ = 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)
}
)
2
Answers
I needed to create class attributes.
handle
andoauthswift
are declared as attributes of the class and now the code works. Revised code below:This is not the answer to your question.
But try using the Fabric for install TwitterKit.
For me personally this is an easier way.