【发布时间】: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