[GH-ISSUE #524] OAuthSwift - The operation couldn’t be completed. (OAuthSwiftError error -11.) #343

Closed
opened 2026-03-03 16:47:55 +03:00 by kerem · 4 comments
Owner

Originally created by @wikydtron on GitHub (Mar 28, 2019).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/524

Description:

I'm trying to send GPX file to Strava but when I send it via in-app I get this error message.
Here's some of my code:

    func saveWorkout(_ workout: FirebaseWorkout, completion: @escaping (_ success: Bool, _ error: Error?) -> Void) {
        let _gpxString = workout.getGpx()

        do {
            let documentsDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
            let fileURL = documentsDir.appendingPathComponent("workoutdata").appendingPathExtension("gpx")

            print("File Path: \(fileURL.path)")

            try _gpxString.write(to: fileURL, atomically: true, encoding: String.Encoding.utf8)

            let opts: [String: Any?] = [
                "file": fileURL.path,
                "data_type": "gpx",
                "name": workout.name
            ]

            if self.isAuthorized && userSettings.membership.hasFullAccess {
                workoutLib().analyticsEvent(kEventCategoryThirdParty, eventAction: "SAVE_WORKOUT", eventLabel: ThirdPartyApplication.strava.rawValue, eventValue: 1)
                workoutLib().debugLog("Strava: Save Workout")
                self.refreshTokenIfNeeded {
                    _ = self.oauthswift.client.post("https://www.strava.com/api/v3/uploads", parameters: opts as OAuthSwift.Parameters, success: { (_) in
                        workoutLib().debugLog("Strava: Save Workout Success")
                        completion(true, nil)
                    }) { (error) in
                        workoutLib().debugLog("Strava: Save Workout \(error.localizedDescription)")
                        completion(false, error)
                    }
                }
            } else {
                completion(false, nil)
            }

        } catch {
            workoutLib().analytics("GPX_CONVERT_CATCH_ERROR", debug: true, timestamp: true, doPrint: true)
            // failed to write file – bad permissions, bad filename, missing permissions, or more likely it can't be converted to the encoding
            print("error: \(error.localizedDescription)")
            completion(false, nil)
        }
    }

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

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

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

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

Xcode version:

  • 9.3 (Swift 4.1)
  • 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.)
    10.1
  • objective c
Originally created by @wikydtron on GitHub (Mar 28, 2019). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/524 ### Description: I'm trying to send GPX file to Strava but when I send it via in-app I get this error message. Here's some of my code: ``` func saveWorkout(_ workout: FirebaseWorkout, completion: @escaping (_ success: Bool, _ error: Error?) -> Void) { let _gpxString = workout.getGpx() do { let documentsDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) let fileURL = documentsDir.appendingPathComponent("workoutdata").appendingPathExtension("gpx") print("File Path: \(fileURL.path)") try _gpxString.write(to: fileURL, atomically: true, encoding: String.Encoding.utf8) let opts: [String: Any?] = [ "file": fileURL.path, "data_type": "gpx", "name": workout.name ] if self.isAuthorized && userSettings.membership.hasFullAccess { workoutLib().analyticsEvent(kEventCategoryThirdParty, eventAction: "SAVE_WORKOUT", eventLabel: ThirdPartyApplication.strava.rawValue, eventValue: 1) workoutLib().debugLog("Strava: Save Workout") self.refreshTokenIfNeeded { _ = self.oauthswift.client.post("https://www.strava.com/api/v3/uploads", parameters: opts as OAuthSwift.Parameters, success: { (_) in workoutLib().debugLog("Strava: Save Workout Success") completion(true, nil) }) { (error) in workoutLib().debugLog("Strava: Save Workout \(error.localizedDescription)") completion(false, error) } } } else { completion(false, nil) } } catch { workoutLib().analytics("GPX_CONVERT_CATCH_ERROR", debug: true, timestamp: true, doPrint: true) // failed to write file – bad permissions, bad filename, missing permissions, or more likely it can't be converted to the encoding print("error: \(error.localizedDescription)") completion(false, nil) } } ``` ### OAuth Version: - [ ] Version 1 - [X] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [X] CocoaPods - [ ] Manually ### Library version: - [ ] head - [ ] v1.2.1 - [ ] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [ ] 9.3 (Swift 4.1) - [ ] 9.0 (Swift 4.0) - [ ] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [X] other: (Please fill in the version you are using.) 10.1 - [ ] objective c
kerem closed this issue 2026-03-03 16:47:55 +03:00
Author
Owner

@abinrm commented on GitHub (Apr 29, 2019):

I get this same error when I receive http response code 400 a response, I still don't know how to extract the response code from OAuthSwiftError. Whats your response code?

<!-- gh-comment-id:487525470 --> @abinrm commented on GitHub (Apr 29, 2019): I get this same error when I receive http response code 400 a response, I still don't know how to extract the response code from OAuthSwiftError. Whats your response code?
Author
Owner

@phimage commented on GitHub (Apr 30, 2019):

@abinrm you don't know because you do not read response at your question or do not know how to use swift error...
please do not pollute other topic

@wikydtron you do not receive only "The operation couldn’t be completed. (OAuthSwiftError error -11.)"
You receive a well typed error OAuthSwiftError.requestError, then there is more information in the network error. print all error, not .localizedDescription
see https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuthSwiftError.swift#L34

<!-- gh-comment-id:487933228 --> @phimage commented on GitHub (Apr 30, 2019): @abinrm you don't know because you do not read response at your question or do not know how to use swift error... please do not pollute other topic @wikydtron you do not receive only "The operation couldn’t be completed. (OAuthSwiftError error -11.)" You receive a well typed error OAuthSwiftError.requestError, then there is more information in the network error. print all error, not .localizedDescription see https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuthSwiftError.swift#L34
Author
Owner

@SixFiveSoftware commented on GitHub (Jun 6, 2019):

I received this exact error as well when accessing Twitter's OAuth1 API, and in my case, I hooked up my Charles Proxy and found that I was receiving an error with:

{
	"errors": [{
		"code": 89,
		"message": "Invalid or expired token."
	}]
}

...which was slightly different than the -11 error, but was directly related in the proxy output and the error seen by OAuthSwift.

Searching around online, I found other articles that suggested recreating the OAuth manager instance with the consumer key and secret, and try again. So far, this has worked for us, but time may tell. Something inside the OAuth manager might have been cached such that a new instance cleared it up. Hope this helps.

<!-- gh-comment-id:499527473 --> @SixFiveSoftware commented on GitHub (Jun 6, 2019): I received this exact error as well when accessing Twitter's OAuth1 API, and in my case, I hooked up my Charles Proxy and found that I was receiving an error with: ``` { "errors": [{ "code": 89, "message": "Invalid or expired token." }] } ``` ...which was slightly different than the `-11` error, but was directly related in the proxy output and the error seen by OAuthSwift. Searching around online, I found other articles that suggested recreating the OAuth manager instance with the consumer key and secret, and try again. So far, this has worked for us, but time may tell. Something inside the OAuth manager might have been cached such that a new instance cleared it up. Hope this helps.
Author
Owner

@phimage commented on GitHub (Jun 10, 2019):

Just to clarify one time again, then I close

                switch error {
                case .requestError(let networkError, let request): // -11
                    break // do something with your networkError
                default:
                    break // do something
                }
<!-- gh-comment-id:500304049 --> @phimage commented on GitHub (Jun 10, 2019): Just to clarify one time again, then I close ```swift switch error { case .requestError(let networkError, let request): // -11 break // do something with your networkError default: break // do something } ```
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#343
No description provided.