【问题标题】:Uber /v1/payment-methods - giving error "Unauthorized" with Available scopes emptyUber /v1/payment-methods - 给出错误“未经授权”,可用范围为空
【发布时间】:2017-01-14 14:33:01
【问题描述】:

我正在使用 Uber API 并尝试从 here 获取付款信息​​并收到以下错误,我不知道为什么。

httpget 响应:未经授权 {"message":"至少需要一个范围。可用范围:","code":"unauthorized"}

我正在使用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 请求完全访问权限吗?

请告知..提前谢谢。

【问题讨论】:

    标签: java google-app-engine uber-api


    【解决方案1】:

    不再有 payment_method 范围。您只需要“请求”范围即可访问付款方式端点。您可以从示例中删除 Ride_widgets 和 payment_methods 范围并添加“请求”,它应该可以工作。

    您使用的 sdk 看起来有点过时,所以我建议尽可能更新。

    在付款方式文档中查看更多详细信息:https://developer.uber.com/docs/rides/api/v1-payment-methods

    由于这是一个特权范围,您可以将其用于您的开发者帐户,但需要在开发者仪表板中请求完全访问权限,以便所有用户在生产环境中访问。

    【讨论】:

    • 感谢 Dustin .. 感谢您的帮助 ... 按照建议删除所有并添加请求范围 .. return new SessionConfiguration.Builder() .setClientId(clientId) .setClientSecret(clientSecret) .setRedirectUri(REDIRECT_URI) .setScopes(Collections.singletonList(Scope.REQUEST)) .build();
    • 知道如何传递多个范围吗?因为我尝试的方法不起作用..我可以通过 scope.PROFILE 或 scope.REQUEST ........但我真的需要两者..来访问用户个人资料和付款选项等 - 任何想法。 .........我在我的问题中尝试了上面的代码示例..但它真的没有接受它。
    • 没关系,我明白了.. 如果有人需要它.. 只需像这样传递多个范围.. ArrayList scope_list = new ArrayList (); scope_list.add(Scope.REQUEST); scope_list.add(Scope.PROFILE);
    • 它不起作用。我有一个具有以下范围的访问令牌:"token_type":"Bearer","scope":"profile ride_widgets request places",我从GET /payment-methods API 端点获得{"message":"This endpoint requires at least one of the following scopes: payment_baidu_wallet, payment_methods.write","code":"unauthorized"}。使用生产 Uber API URL api.uber.com,并且请求范围权限被授予完全访问权限。向用户请求授权时,我没有传递任何范围。
    • 将值为profile places request的范围参数添加到授权端点会导致与上述相同的错误。
    猜你喜欢
    • 2017-03-03
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    • 2017-04-23
    • 2021-12-09
    • 2019-07-07
    相关资源
    最近更新 更多