Pezze
Pezze

Reputation: 771

Connect more than one project id to the Google Play Developer Console

When I try to execute a request for a Google developer API. purchases(). products(). get() I receive a 403 error: projectNotLinked.

The message tells me "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."

At this point I can go to the console, unlink a previous project, and link this one, run the code, and the code works.

However, I cannot unlink permanently the previous project: I need to keep them both linked. How do I solve this problem?

I looked around and couldn't find a solution. Tried to call Google, and they told me that they do not support this kind of requests.

Thanks in advance.

Upvotes: 8

Views: 4491

Answers (2)

iltempo
iltempo

Reputation: 16012

To reemphasise @andy's comment: There can only be one single linked API project.

I spend quite some time to find this out. Google's documentation is not helpful here.

If you need access to multiple projects/applications, you have to create multiple service accounts inside of the single linked API project and manages access to apps individually.

Upvotes: 12

Longmang
Longmang

Reputation: 1663

Andy's comment is correct, I find the description LINKED PROJECT in the Google Play Developer Console confusing at best.

However, I setup in the Google Developers Console a company project with the appropriate Server Keys and Service accounts. It isn't ideal, but it works. You can then assign permission to the required service account back in the Google Play Developer Console.

You can also setup just one key and service account if that makes it simpler and the use them as shown below in PHP for a server

$service_account_name = '[email protected]';
$key_file_location = somedir/keyfile.p12;

$client = new Google_Client();
$client->setApplicationName("GoogleDevelopersConsoleProjectName");
$service = new Google_Service_AndroidPublisher($client);

$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
    $service_account_name,
    array('https://www.googleapis.com/auth/androidpublisher'),
    $key
);

$client->setAssertionCredentials($cred);

if($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion($cred);
}  

$apiKey = "GoogleDevelopersConsoleServerKey";
$client->setDeveloperKey($apiKey);

$package_name = "com.yourcompany.yourappname1";

Then all you need to do for the other application is change the $package_name.

$package_name = "com.yourcompany.yourappname2";

Then using the Google Service AndroidPublisher to query subscriptions

$service = new Google_Service_AndroidPublisher($client);

$results = $service->purchases_subscriptions->get($package_name,$subscriptionId,$token,array());

You can also start to assign multiple keys, service accounts and other credentials you add other projects in the Google Play Developer Console.

Upvotes: 6

Related Questions