5

I'm integrating google play in-app subscription in my app. To access google API, first I need to get an access_token and then use it in header for accessing subscription APIs. Following the procedure (Android : inApp purchase receipt validation google play) I got my credentials file which looks like following

{
  "type": "service_account",
  "project_id": "my-project-id",
  "private_key_id": "x",
  "private_key": "-----BEGIN PRIVATE KEY-----y-----END PRIVATE KEY-----\n",
  "client_email": "google-play-developer@z.iam.gserviceaccount.com",
  "client_id": "x",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google-play-developer%40y.iam.gserviceaccount.com"
}

Note: real ids and values are replaced with x, y and z

Next to exchange JWT for an access_tokenm i'm using Google APIs client library for php https://github.com/googleapis/google-api-php-client

Here is the my code

$client = new \Google_Client();
$client->setAuthConfig('client_secret.json');
$client->addScope('https://www.googleapis.com/auth/androidpublisher');
$client->setRedirectUri($request->redirect_uri);
$token = $client->fetchAccessTokenWithAuthCode($request->code);

But i cannot get access token. Getting following error

{
    "error": "invalid_request",
    "error_description": "Could not determine client ID from request."
}
marslanayyoob
  • 81
  • 1
  • 5

0 Answers0