Uber Invalid OAuth 2.0 credentials provided Uber Authentication In ios Swift

后端 未结 3 504
野性不改
野性不改 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 04:49

    Finally I have done it :)

    I changed the method like below and it Worked

    func callRequestAPI(url:String){
    
        var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        var session = NSURLSession(configuration: configuration)
    
        let params:[String: AnyObject] = [
            "product_id" : selectedUberProductId,
            "start_latitude" : start_lat,
            "start_longitude" : start_lng,
            "end_latitude" : end_lat,
            "end_longitude" : end_lng]
    
    
    
        let request = appDelegate.oauth.request(forURL: NSURL(string:url)!)
        request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
        request.HTTPMethod = "POST"
        var err: NSError?
        request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions.allZeros, error: &err)
    
        let task = session.dataTaskWithRequest(request) {
            data, response, error in
    
            if let httpResponse = response as? NSHTTPURLResponse {
                if httpResponse.statusCode != 202 {
                    println("response was not 202: \(response)")
    
                    return
                }
            }
            if (error != nil) {
                println("error submitting request: \(error)")
                return
            }
    
            // handle the data of the successful response here
            var result = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.allZeros, error: nil) as! NSDictionary
    
    
            println(result)
    
            if let request_id: String = result["request_id"] as? String{
    
                println(request_id)
            }
    
            if let driver: String = result["driver"] as? String{
    
                println(driver)
            }
    
            if let eta: Int = result["eta"] as? Int{
    
                println(eta)
            }
    
            if let location: String = result["location"] as? String{
    
                println(location)
            }
    
    
            if let status: String = result["status"] as? String{
    
                println(status)
            }
    
    
            if let surge_multiplier: Int = result["surge_multiplier"] as? Int{
    
                println(surge_multiplier)
            }
    
            if let vehicle: String = result["vehicle"] as? String{
    
                println(vehicle)
            }
    
        }
    
        task.resume()
    
    }
    

    here is the Response I Got, Parsing is also given in my above method

    {
      driver = "";
      eta = 15;
      location = "";
      "request_id" = "ea39493d-b718-429f-8710-00a34dcdaa93";
      status = processing;
      "surge_multiplier" = 1;
      vehicle = "";
    }
    

    Enjoy

提交回复
热议问题