I had the same problem, and in the end I found that at the moment the service accounts cannot access the Play API.
I'm not sure when Google plans to fix this, but you can get around this by creating a web application client ID and setting up a basic login page to first create the code using the new client data of the web application and go to $ client-> createAuthUrl ( ):
$client = new apiClient(); $key = file_get_contents(KEY_FILE); $client->setClientId(CLIENT_ID); $client->setClientSecret(CLIENT_SECRET); $client->setRedirectUri(MY_WEBAPP_URL); $client->setDeveloperKey($key); $client->setScopes(array('https://www.googleapis.com/auth/androidpublisher')); $authUrl = $client->createAuthUrl(); print "<a class='login' href='$authUrl'>Connect Me!</a>";
This will lead you to the Google login page, where you must log in with the developer account. When you authorize the application, it will return you to the URL of your web application, as defined when setting the client ID using CODE as the get parameter. You can use to create a token (and, more importantly, an update token):
$url = 'https://accounts.google.com/o/oauth2/token'; $fields = array( 'grant_type'=>'authorization_code', 'code'=>$code, 'client_id'=>CLIENT_ID, 'client_secret'=>CLIENT_SECRET, 'redirect_uri'=>MY_WEBAPP_URL );
This should return you JSON data with an update token. Save this token and use it to make another call when you need to create an access token. You essentially run the same code as you to get the update token, but with different fields:
$fields = array( 'grant_type'=>'refresh_token', 'refresh_token'=>$refresh_token, 'client_id'=>CLIENT_ID, 'client_secret'=>CLIENT_SECRET, );
This will give you an access token that you can use to obtain purchase data at the following URL: https://www.googleapis.com/androidpublisher/v1/applications/[PACKAGE]/subscriptions/[SKU]/purchases/[PURCHASE_TOKEN]?access_token=[ACCESS_TOKEN]
The trick gets the update token as soon as you have that everything else should be pretty simple.
Ahmed
source share