Uber Invalid OAuth 2.0 credentials provided Uber Authentication In ios Swift

后端 未结 3 495
野性不改
野性不改 2020-12-16 04:18

I\'m implementing the Uber\'s Request Endpoint in my iOS (Swift) App. The Request API/Endpoint requires the user authentication with the app, here is the doc.

For th

3条回答
  •  暖寄归人
    2020-12-16 05:00

    Updated for Swift 2. I used the same setup and library for oauth that Qadir describes in his question. I updated his request to work in Swift 2. Hope this helps others.

    uberRequest:

        let params:[String:AnyObject] = [
            "product_id" : uberProduct,
            "start_latitude" : userLat,
            "start_longitude" : userLng,
            "end_latitude" : barLat,
            "end_longitude" : barLng]
    
        let urlPath = "https://sandbox-api.uber.com/v1/requests"
        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        var session = NSURLSession(configuration: configuration)
    
        guard let endpoint = NSURL(string: urlPath) else { print("Error creating endpoint");return }
    
        let request = appDelegate.oauth.request(forURL: NSURL(string:urlPath)!)
        request.setValue("application/json; charset=utf-8", forHTTPHeaderField:"Content-Type")
    
        request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions.PrettyPrinted)
    
        request.HTTPMethod = "POST"
    
        print("Prepare to make request -> \(request)")
    
        let task = NSURLSession.sharedSession().dataTaskWithRequest(request){ data, response, error in
            if error != nil{
                print("Error -> \(error)")
                return
            }
    
            do {
                let result = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)
    
                print("Result -> \(result)")
    
            } catch {
                print("Error -> \(error)")
            }
        }
    
        task.resume()
    

    It returns:

    Result -> Optional(["driver": , "request_id": 5834384c-7283-4fe6-88a7-e74150c6ab30, "surge_multiplier": 1, "location": , "vehicle": , "status": processing, "eta": ])
    

提交回复
热议问题