0

我正在开发一个带有应用内购买的应用,所以我想知道订阅是否过期。我已经有了我的 RefreshToken 和 AccessToken,但是当我试图根据这个获取订阅信息时,我总是得到同样的错误:{“error”:{“errors”:[
{“domain”:“global” ,
“原因”:“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();
        }

请帮忙 ((

4

1 回答 1

0

参考RFC 6750,“Bearer”和令牌之间需要有一个空格。

将您的代码更改为:

post.setHeader("Authorization" , "Bearer " + accessToken);
于 2018-11-07T20:04:08.293 回答