7

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?

Community
  • 1
  • 1
Mark
  • 71
  • 1
  • 1
  • 3

1 Answers1

3

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 :)

Krtko
  • 1,055
  • 18
  • 24
  • 1
    Your answer helped me - there's lot of advice out there about refresh tokens etc, but I was using a service account and didn't feel this was applicable to me. Simply reviewing the permissions indicated that I didn't have 'financial' permissions which prevented me verifying the google play in app purchases. Thanks @krtko – RobbiewOnline Dec 30 '16 at 16:52
  • @DevologyLtd does this mean that since you are using a service account that you have to ALSO authenticate with ouath and do all that token stuff as well? – TheLettuceMaster Oct 07 '18 at 18:28
  • Hi @KickingLettuce As far as I can remember there was no oAuth/token stuff - I just needed to add the permissions I needed. – RobbiewOnline Oct 08 '18 at 18:31
  • 1
    @DevologyLtd Thanks for the response. I finally got behind my issue and it was unrelated to how I was authorizing (I used an in-app purchase created before linking my accounts). In the end, I did not have to do anything with access_tokens. Only authorizing my service account using the JWT. – TheLettuceMaster Oct 08 '18 at 19:22