Google play API返回错误
问题描述:
我遇到了与this postGoogle play API返回错误
中所述相同的问题。我们已经使用了几乎完全相同的代码。我已经在下面试图用两个客户端ID和谷歌的服务帐户的电子邮件地址mehotd
setServiceAccountId(GOOGLE_SERVICE_CLIENT_EMAIL) OR
setServiceAccountId(GOOGLE_CLIENT_ID)
误差变化在的A/C ID的变化。如果我使用的客户端ID,错误是
400错误的请求{ “错误”: “invalid_grant”}
,如果我使用的服务的电子邮件ID,错误是
401 Unauthorized {
"code" : 401, "errors" : [ {
"domain" : "androidpublisher",
"message" : "This developer account does not own the application.",
"reason" : "developerDoesNotOwnApplication" } ], "message" : "This developer account does not own the application." }
任何理念?
答
似乎有一些证据表明Google Play API目前不能与服务帐户(疯狂)一起使用。有关于问题here的另一个线程。您可以阅读Google服务帐户here。您可以阅读关于Android版Google Play API here的身份验证。
一旦你完成了对谷歌API控制台的舞蹈获得refresh_token你可以得到一个访问令牌是这样的:
private String getAccessToken()
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://accounts.google.com/o/oauth2/token");
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("grant_type", "refresh_token"));
nameValuePairs.add(new BasicNameValuePair("client_id", "YOUR_CLIENT_ID);
nameValuePairs.add(new BasicNameValuePair("client_secret", "YOUR_CLIENT_SECRET"));
nameValuePairs.add(new BasicNameValuePair("refresh_token", "YOUR_REFRESH_TOKEN"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
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());
return json.getString("access_token");
}
catch (IOException e) { e.printStackTrace(); }
catch (JSONException e) { e.printStackTrace(); }
return null;
}
你有没有找到一个解决办法? – Kalina