android - 无法通过 Google API 授权
问题描述
我正在开发一个带有应用内购买的应用,所以我想知道订阅是否过期。我已经有了我的 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();
}
请帮忙 ((
解决方案
参考RFC 6750,“Bearer”和令牌之间需要有一个空格。
将您的代码更改为:
post.setHeader("Authorization" , "Bearer " + accessToken);
推荐阅读
- r - 通过堆积条形图中的数值变量对具有分类变量的列进行排序
- javascript - 如果身体有灰度滤镜,有没有办法让图像具有原始颜色?
- java - 如何使用 GeckoDriver Firefox 和 Selenium 下载文件?
- java - 使用spring Mapper映射Map的对象-Java
- typescript - 打字稿转译器不应该至少警告从超类构造函数调用虚拟方法吗?
- c# - NServiceBus 命令处理程序中的生产者/消费者
- reactjs - Create-react-app 生成命令未找到
- websocket - 是否可以捕获 signalR 连接断开事件?错误:连接断开,错误 webSocket 关闭,状态码:1006
- c# - 如何在复杂的异步等待场景中实现超时和取消
- powerbi - 根据另一个表中的度量查找列中的值