[GH-ISSUE #441] OAuthSwiftError error -10 With Twitter #288

Closed
opened 2026-03-03 16:47:24 +03:00 by kerem · 5 comments
Owner

Originally created by @ejwalters on GitHub (Mar 4, 2018).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/441

Description: I am attempting to connect to Twitter via OAuth1 and I am getting an error saying "The operation couldn’t be completed. (OAuthSwiftError error -10.)". It seems that I am getting caught in the error handler of the authorize method. My code seems to match the examples so I am not sure what I am missing. Here is the code:

override func viewDidLoad() {
        super.viewDidLoad()
        
        print("BEFORE OAUTHSWIFT")
        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"
        )
        print("AFTER OAUTHSWIFT")
        let _ = oauthswift.authorize(
            withCallbackURL: URL(string: "http://codepath.com")!,
            success: { credential, response, parameters in
                print(credential.oauthToken)
                print(credential.oauthTokenSecret)
                print(parameters["user_id"]!)
                // Do your request
        },
            failure: { error in
                print(error.localizedDescription)
                print("ERROR")
        }
        )
        // Do any additional setup after loading the view, typically from a nib.
    }

OAuth Provider (Twitter, Github, ..): Twitter

OAuth Version:

  • [ x] Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • [ x] Manually

Library version:

  • head
  • [ x] v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • [ x] 9.0 (Swift 4.0)

  • 9.0 (Swift 3.2)

  • 8.x (Swift 3.x)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @ejwalters on GitHub (Mar 4, 2018). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/441 ### Description: I am attempting to connect to Twitter via OAuth1 and I am getting an error saying "The operation couldn’t be completed. (OAuthSwiftError error -10.)". It seems that I am getting caught in the error handler of the authorize method. My code seems to match the examples so I am not sure what I am missing. Here is the code: ``` override func viewDidLoad() { super.viewDidLoad() print("BEFORE OAUTHSWIFT") 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" ) print("AFTER OAUTHSWIFT") let _ = oauthswift.authorize( withCallbackURL: URL(string: "http://codepath.com")!, success: { credential, response, parameters in print(credential.oauthToken) print(credential.oauthTokenSecret) print(parameters["user_id"]!) // Do your request }, failure: { error in print(error.localizedDescription) print("ERROR") } ) // Do any additional setup after loading the view, typically from a nib. } ``` ### OAuth Provider (Twitter, Github, ..): Twitter ### OAuth Version: - [ x] Version 1 - [ ] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [ ] CocoaPods - [ x] Manually ### Library version: - [ ] head - [ x] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [ x] 9.0 (Swift 4.0) - [ ] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:47:24 +03:00
Author
Owner

@phimage commented on GitHub (Mar 4, 2018):

let _ =
This is the error...

<!-- gh-comment-id:370233331 --> @phimage commented on GitHub (Mar 4, 2018): let _ = This is the error...
Author
Owner

@ejwalters commented on GitHub (Mar 4, 2018):

I changed it to this and I get the same result:

let handle = oauthswift.authorize(
            withCallbackURL: URL(string: "http://codepath.com")!,
            success: { credential, response, parameters in
                print(credential.oauthToken)
                print(credential.oauthTokenSecret)
                print(parameters["user_id"]!)
                // Do your request
        },
            failure: { error in
                print(error.localizedDescription)
                print("ERROR")
        }
        )
<!-- gh-comment-id:370233469 --> @ejwalters commented on GitHub (Mar 4, 2018): I changed it to this and I get the same result: ``` let handle = oauthswift.authorize( withCallbackURL: URL(string: "http://codepath.com")!, success: { credential, response, parameters in print(credential.oauthToken) print(credential.oauthTokenSecret) print(parameters["user_id"]!) // Do your request }, failure: { error in print(error.localizedDescription) print("ERROR") } ) ```
Author
Owner

@phimage commented on GitHub (Mar 4, 2018):

And Xcode say nothing?
That’s an error too

The object must be retain in memory, like an attribute of the class
Alternatively you can put oauthswift object as class attribute

This is an asynchronous code with no strong reference, to allow to free memory

<!-- gh-comment-id:370233816 --> @phimage commented on GitHub (Mar 4, 2018): And Xcode say nothing? That’s an error too The object must be retain in memory, like an attribute of the class Alternatively you can put oauthswift object as class attribute This is an asynchronous code with no strong reference, to allow to free memory
Author
Owner

@ejwalters commented on GitHub (Mar 4, 2018):

XCode does generate a warning of "Intialization of immutable value 'handle'..." when i use let handle = . I was using the code from the sample. Changed the code to this and it worked. Thanks!

    override func viewDidLoad() {
        super.viewDidLoad()
        var oauthswift: OAuth1Swift!
        var handle: OAuthSwiftRequestHandle!
        
        print("BEFORE OAUTHSWIFT")
        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"
        )
        print("AFTER OAUTHSWIFT")
        handle = oauthswift.authorize(
            withCallbackURL: URL(string: "http://codepath.com")!,
            success: { credential, response, parameters in
                print(credential.oauthToken)
                print(credential.oauthTokenSecret)
                print(parameters["user_id"]!)
                // Do your request
        },
            failure: { error in
                print(error.localizedDescription)
                print(handle)
        }
        )
        // Do any additional setup after loading the view, typically from a nib.
    }
<!-- gh-comment-id:370235162 --> @ejwalters commented on GitHub (Mar 4, 2018): XCode does generate a warning of "Intialization of immutable value 'handle'..." when i use `let handle = `. I was using the code from the sample. Changed the code to this and it worked. Thanks! ``` override func viewDidLoad() { super.viewDidLoad() var oauthswift: OAuth1Swift! var handle: OAuthSwiftRequestHandle! print("BEFORE OAUTHSWIFT") 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" ) print("AFTER OAUTHSWIFT") handle = oauthswift.authorize( withCallbackURL: URL(string: "http://codepath.com")!, success: { credential, response, parameters in print(credential.oauthToken) print(credential.oauthTokenSecret) print(parameters["user_id"]!) // Do your request }, failure: { error in print(error.localizedDescription) print(handle) } ) // Do any additional setup after loading the view, typically from a nib. } ```
Author
Owner

@phimage commented on GitHub (Mar 4, 2018):

Do not use “!”
Bad practice
Use swiftlint to see all bad practice when coding in swift

I expect that the “var” are in class scope and not viewDidLoad scope
Or you will have same issue one day

<!-- gh-comment-id:370235402 --> @phimage commented on GitHub (Mar 4, 2018): Do not use “!” Bad practice Use swiftlint to see all bad practice when coding in swift I expect that the “var” are in class scope and not viewDidLoad scope Or you will have same issue one day
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#288
No description provided.