2016-11-07 16 views
0

私はMac OSXアプリケーションを構築しようとしていますUBER.IのためにAouth2のすべてのステップを完了しました。私は正常にaccess_tokenを取得しています。私はまた、ユーザーのプロファイルと履歴を取得することができますが、私は "乗ってリクエスト"を投稿しようとしている間、私は401許可されていないエラーresponse.pleaseヘルプを取得しています。 私のコードは以下の通りです。uber api ride要求を取得する401 unautherizedエラー応答

**

//POST /v1/requests 
    NSString *[email protected]"https://sandbox-api.uber.com/v1"; 
    NSString *url = [NSString stringWithFormat:@"%@/requests", sandBoxURL]; 

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]]; 
    [request addValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [request addValue:[NSString stringWithFormat:@"Bearer %@", _accessToken] forHTTPHeaderField:@"Authorization"]; 

    NSError *error = nil; 
    request.HTTPMethod = @"POST"; 
    request.HTTPBody = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; 
    NSLog(@"Request for Product Request:%@",request); 
    [self performNetworkOperationWithRequest:request completionHandler:^(NSDictionary *requestDictionary, NSURLResponse *response, NSError *error) 
    { 
     NSLog(@"Response for Product Request:%@",response); 
     NSLog(@"Result:%@",requestDictionary); 
     NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; 
     if (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300) 
     { //OK 
      UberRequest *requestResult = [[UberRequest alloc] initWithDictionary:requestDictionary]; 
      // handler(requestResult, response, error); 
     } 
     if (409 == httpResponse.statusCode) { //needs surge confirmation 
      NSLog(@"Surge Conflict"); 
     } 
     else 
     { 
      NSLog(@"Error In response"); 

     } 
    }]; 

** と応答、私は取得しています:

{ URL: https://sandbox-api.uber.com/v1/requests } { status code: 401, headers { 
    Connection = "keep-alive"; 
    "Content-Length" = 83; 
    "Content-Type" = "application/json"; 
    Date = "Mon, 07 Nov 2016 11:19:35 GMT"; 
    Server = nginx; 
    "Strict-Transport-Security" = "max-age=0"; 
    "X-Content-Type-Options" = nosniff; 
    "X-Uber-App" = "uberex-sandbox, migrator-uberex-sandbox-optimus"; 
    "X-Uber-Missing-Scopes" = true; 
    "X-XSS-Protection" = "1; mode=block"; 
} } 
Result:{ 
    code = unauthorized; 
    message = "Requires at least one scope. Available scopes: "; 
} 
+0

リクエストスコープのトークンをリクエストしましたか? https://developer.uber.com/docs/ride-requests/guides/scopes –

+0

私は開発者のアカウントでログインしようとしているため、スコープをリクエストする必要があります。 –

+0

はい、トークンには「要求」スコープが必要です。 –

答えて

0

私は解決策を得ました。私のスコープ入力に問題があった。あなたがログインしているアカウントが開発者であっても、トークンを要求している間はスコープを適切に入れる必要がある。私の場合は、トークンで要求範囲が必要でした。

関連する問題