问题描述
我遇到的问题与
。我们已经使用了几乎完全相同的代码。我已经尝试在以下mehotd中使用客户ID和电子邮件地址
setServiceAccountId(GOOGLE_SERVICE_CLIENT_EMAIL)或
setServiceAccountId(GOOGLE_CLIENT_ID)
错误随着a / c id的变化而变化。如果我使用客户端ID,错误是
lockquote
400错误请求{error:invalid_grant}
如果我使用服务电子邮件ID,错误是
401未经授权{
code:401,errors:[{
domain:androidpublisher,
message:此开发者帐户不拥有该应用程序。,
reason:developerDoesNotOwnApplication}],message:此开发者帐户不拥有该应用程序。 }
任何想法?
似乎有一些证据表明Google Play API目前不适用于服务帐户(疯狂)。此问题有的问题。您可以阅读。
一旦您在Google API控制台上完成了获取refresh_token的舞蹈,您就可以获得如下所示的访问令牌:
private String getAccessToken()
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(https://accounts.google.com/o/oauth2/token);
尝试
{
列表< 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(); $ b $ for(String line = reader.readLine(); line!= null ; line = reader.readLine())
{
buffer.append(line);
}
JSONObject json = new JSONObject(buffer.toString()) ;
返回json.getString(access_token);
}
catch(IOException e){e.printStackTrace();}
catch(JSONException e){e.printStackTrace ();}
返回null;
}
i am getting the same issue as described in this post
. we have used almost exactly the same code. i have tried both with Client ID and Email address of the google service account in below mehotd
setServiceAccountId(GOOGLE_SERVICE_CLIENT_EMAIL) OR
setServiceAccountId(GOOGLE_CLIENT_ID)
error changes with the change in a/c id. if i use client id, error is
and if i use service email id, error is
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." }
any idea?
There appears to be some evidence that Google Play API does not currently work with Service Accounts (madness). There is another thread on the issue here. You can read about the Google Service Accounts here. You can read about authentication for Android Google Play API here.
Once you have done the dance on the Google API Console to get a refresh_token you can get an access token like this:
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;
}
这篇关于Google Play API返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!