我遇到与this post
中描述的问题相同的问题。我们使用了几乎完全相同的代码。我已尝试使用以下mehotd
中的客户ID和Google服务帐户的电子邮件地址setServiceAccountId(GOOGLE_SERVICE_CLIENT_EMAIL) OR
setServiceAccountId(GOOGLE_CLIENT_ID)
错误随着a / c id的变化而变化。如果我使用客户端ID,错误是
400 Bad Request {“error”:“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." }
任何想法?
答案 0 :(得分:2)
似乎有一些证据表明Google Play API目前不支持服务帐户(疯狂)。问题here还有另一个主题。您可以阅读有关Google服务帐户here的信息。您可以阅读有关Android Google Play API here的身份验证的信息。
在Google 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;
}