Nathan McKaskle
Nathan McKaskle

Reputation: 3083

Why am I getting this error posting a request to the Uber Sandbox? NSURLErrorDomain error -1012

I can get product ID's from the products path but I get this error when trying to post a request to the sandbox schedule a ride. Trying to figure out what I'm doing wrong here. I have the bearer token added. I'm not sure what it wants or what is missing.

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x7f8c13939ed0 {NSErrorFailingURLStringKey=https://sandbox-api.uber.com/v1/requests, NSUnderlyingError=0x7f8c0ac78410 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)", NSErrorFailingURLKey=https://sandbox-api.uber.com/v1/requests}

func performPostUberRequest(url: NSURL, prodId: String) {
    let params:[String: AnyObject] = [
        "start_latitude" : "39.955715",
        "start_longitude" : "-75.1680298",
        "end_latitude" : "39.9542675",
        "end_longitude" : "-75.1409609",
        "product_id": prodId
    ]

    var error: NSError?
    var request: NSMutableURLRequest = NSMutableURLRequest(URL: url)
    request.HTTPMethod = "POST"
    request.addValue("Bearer \(uberToken)", forHTTPHeaderField: "Authorization")
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions.allZeros, error: &error)
    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()){
        response, data, error in
        if let error = error {
            println(error)
        } else if data != nil {
            if let json: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as? NSDictionary {
                println(json)
            }
        }
    }
}

Upvotes: 2

Views: 759

Answers (1)

bolizhou
bolizhou

Reputation: 1218

According to your comments: { code = unauthorized; message = "Missing scope: request"; }, you may miss the scope, which can be specified on your Uber developer dashboard where you registered the app and got the secret and client id and stuff.

If you have done this you should have added the necessary scopes into the parameters when you requested authorization code and access token through OAuth2.0 at the beginning.

In my imeplementation, the scopes were specified as the following:

[[NXOAuth2AccountStore sharedStore] setClientID:_clientID
                                         secret:_clientSecret
                                          scope:[NSSet setWithObjects:@"request", @"history_lite", @"profile", @"request_receipt", nil]
                               authorizationURL:[NSURL URLWithString:@"https://login.uber.com/oauth/authorize"]
                                       tokenURL:[NSURL URLWithString:@"https://login.uber.com/oauth/token"]
                                    redirectURL:[NSURL URLWithString:_redirectURL]
                                  keyChainGroup:nil
                                 forAccountType:_applicationName];

Upvotes: 1

Related Questions