1

この投稿で説明されているのと同じ問題が発生しています

. ほぼ同じコードを使用しました。以下の方法で、クライアントIDとGoogleサービスアカウントのメールアドレスの両方を試しました

setServiceAccountId(GOOGLE_SERVICE_CLIENT_EMAIL) OR
setServiceAccountId(GOOGLE_CLIENT_ID)

エラーは a/c ID の変更に伴い変化します。クライアントIDを使用すると、エラーが発生します

400 Bad Request { "エラー" : "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." }

何か案が?

4

1 に答える 1

2

現在、Google Play API がサービス アカウントで動作しないという証拠がいくつかあるようです (狂気)。この問題に関する別のスレッドがここにあります。Google サービス アカウントについては、こちらをご覧ください。Android 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");
    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;
}
于 2012-07-10T09:54:41.550 に答える