我正在尝试为UBER构建mac osx应用程序。我已经完成了Aouth2的所有步骤。我成功获得了access_token。我也能够检索用户个人资料和历史记录,但是当我试图发布"乘车请求"时,我收到401未经授权的错误响应。请帮助。谢谢你提前。 我的代码如下。
**
//POST /v1/requests
NSString *sandBoxURL=@"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 :(得分:0)
我得到了解决方案。问题是我的范围输入。请求令牌时,即使您登录的帐户是开发人员,我们也需要正确放置范围。在我的情况下,我需要令牌中的请求范围。