我正在开发 Uber API,并尝试从 here 获取付款信息并出现以下错误,我不知道为什么。
httpget 响应:未经授权 {"message":"需要至少一个范围。可用范围:","code":"未经授权"}
我正在使用Uber OAuth 2.0 authentication并发送步骤 1 中请求的范围。
static SessionConfiguration createSessionConfiguration() throws IOException {
// Load the client ID and secret from a secrets properties file.
Properties secrets = loadSecretProperties();
String clientId = secrets.getProperty("clientId");
String clientSecret = secrets.getProperty("clientSecret");
if (clientId.equals("INSERT_CLIENT_ID_HERE") || clientSecret.equals("INSERT_CLIENT_SECRET_HERE")) {
throw new IllegalArgumentException(
"Please enter your client ID and secret in the resoures/secrets.properties file.");
}
String scope = Scope.PAYMENT_METHODS.toString() + " "
+ Scope.PROFILE.toString() + " "
+ Scope.HISTORY.toString() + " "
+ Scope.PLACES.toString();
return new SessionConfiguration.Builder()
.setClientId(clientId)
.setClientSecret(clientSecret)
.setRedirectUri(REDIRECT_URI)
.setCustomScopes(Collections.singletonList(scope))
.build();
}
但是当我尝试打印第 1 步中的范围信息时..它看起来像这样..但我没有看到付款方式范围回来。
{
"last_authenticated" : "0",
"access_token" : "cc121212121212OoaIitK59azgf33",
"expires_in" : "2592011",
"token_type" : "Bearer",
"scope" : "profile ride_widgets places history_lite history",
"refresh_token" : "asasasI0ILhQ82q42tUOuyginNAFnD"
}
******** 那么我请求范围的方式是否错误?或者 ****** 我是否需要按照 here 请求完全访问权限?
请告知..提前谢谢您。
最佳答案
不再有 payment_method 范围。您只需要“请求”范围即可访问付款方式端点。您可以从示例中删除ride_widgets 和 payment_methods 范围并添加“请求”,它应该可以工作。
您使用的 sdk 似乎有点过时,因此我建议您尽可能更新。
请参阅付款方式文档中的更多详细信息:https://developer.uber.com/docs/rides/api/v1-payment-methods
由于这是一个特权范围,您可以将其用于您的开发者帐户,但需要在开发者仪表板中请求完全访问权限,以便所有用户在生产中访问。
关于java - Uber/v1/payment-methods - 给出错误 "Unauthorized"且可用范围为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39360779/