0
我想建立的Mac OSX應用對於UBER.I已完成Aouth2的所有步驟。我正在成功獲取access_token。我也能夠檢索用戶配置文件和歷史記錄,但是當我試圖發佈「騎乘請求」時,我得到401未經授權的錯誤response.please help.Thank您提前。 我的代碼如下。尤伯杯API乘坐請求獲得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: ";
}
你有沒有要求與請求範圍令牌? https://developer.uber.com/docs/ride-requests/guides/scopes –
我是否需要請求範圍,因爲我想用開發人員的帳戶登錄。 –
是的,令牌必須具有「請求」範圍。 –