When I'm using Google API v2, to get an inapp listing, I'm getting the following error when I'm making the API call:
{
"error": {
"errors": [
{
"domain": "androidpublisher",
"reason": "projectNotLinked",
"message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
}
],
"code": 403,
"message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
}
}
I then researched this error and ended up seeing the suggestions on this page, this page, and on this page as well. I followed and double-checked the way the projects get linked there but it did not help.
This is what I did...
In Google Developer Console:
- Used an existing project.
- Went to APIs & auth > APIs.
- Ensured "Google Play Android Developer API" was turned ON.
- Used my existing credentials for CLIENT ID, CLIENT SECRET, and REDIRECT URIS. Application type was "native application".
- Created an API KEY as well, but did not use it.
In Google Play Developer Console:
- Went to SETTINGS > API access.
- Under LINKED PROJECT, I ensured the above project from the Google Developer Console was linked.
In my PHP script:
<?php
require_once('/var/www/html/common/include.php');
require_once realpath(dirname(__FILE__) . '/lib/Google/autoload.php');
$refreshToken = '1/sometoken';
$packageName = 'com.somepackage';
$client_id = GOOGLE_CLIENT_ID;
$client_secret = GOOGLE_CLIENT_SECRET;
$redirect_uri = 'http://localhost';
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->setScopes(['https://www.googleapis.com/auth/androidpublisher']);
$client->refreshToken($refreshToken);
$service = new Google_Service_AndroidPublisher($client);
$response = $service->inappproducts->listInappproducts($packageName);
var_dump($service);
Which led to the above error.
Any other suggestions to resolve this error with using refresh tokens?