【问题标题】:Can't go through Google API Authorization无法通过 Google API 授权
【发布时间】:2018-10-24 17:06:53
【问题描述】:

我正在开发一个包含应用内购买的应用,所以我想知道订阅是否过期。我已经有了我的 RefreshToken 和 AccessToken,但是当我尝试根据this 获取订阅信息时,我总是遇到同样的错误: {“错误”:{“错误”:[
{“域”:“全球”,
“原因”:“authError”,
“消息”:“无效的凭据”,
"locationType": "标题",
"位置": "授权" } ],
“代码”:401,
“消息”:“无效凭据”}}

我的代码放在这里:

 String urlt = " https://www.googleapis.com/androidpublisher/v3/applications/" + PACKAGE_NAME + "/purchases/subscriptions/" + SUBSCR_ID + "/tokens/" + accessToken;
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet post = new HttpGet(urlt);
        post.setHeader("Scope" , "https://www.googleapis.com/auth/androidpublisher");
        post.setHeader("Authorization" , "Bearer" + accessToken);
        try {
            org.apache.http.HttpResponse response = client.execute(post);
            BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer buffer = new StringBuffer();
            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                buffer.append(line);
            }

            JSONObject json = new JSONObject(buffer.toString());
           int x = 0;
        }
        catch (Exception e) {
            e.printStackTrace();
        }

请帮忙((

【问题讨论】:

  • 引用RFC 6750,“Bearer”和token之间需要有一个空格。
  • 另外,“Scope”标头没有任何作用。 Google 会将您的访问令牌与您在进行身份验证时指定的范围相关联。

标签: android google-api authorization google-authentication in-app-subscription


【解决方案1】:

引用RFC 6750,“Bearer”和token之间需要有一个空格。

将您的代码更改为:

post.setHeader("Authorization" , "Bearer " + accessToken);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-14
    • 2019-07-18
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    相关资源
    最近更新 更多