In Google API v2, why is the error "The project id used to call the Google Play Developer API has not been linked" happening?

Mark picture Mark · Feb 27, 2015 · Viewed 8.3k times · Source

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:

  1. Used an existing project.
  2. Went to APIs & auth > APIs.
  3. Ensured "Google Play Android Developer API" was turned ON.
  4. Used my existing credentials for CLIENT ID, CLIENT SECRET, and REDIRECT URIS. Application type was "native application".
  5. Created an API KEY as well, but did not use it.

In Google Play Developer Console:

  1. Went to SETTINGS > API access.
  2. 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?

Answer

Krtko picture Krtko · Apr 3, 2015

Hey I was having a similar issue as you, I figured out the problem was I was the authenticating a user did not have the right permissions.

First go into your Google Play Console, go under Settings> API Access. Make sure that you have a linked "Google Play Android Developer" (which is sounds like you do and I did as well).

Next go into Settings>User Accounts and Rights, make sure the user has the proper rights to view subscriptions or whatever you need it to. For testing purposes just give it all the rights.

Then make sure to Authenticate this user via Oauth(ie select their email from the list) and then get typical refresh/access token

Really seems so painfully obvious to me now, but it still took a day of frustration. I hope this solves your issue :)