将多个项目 ID 连接到 Google Play Developer Console

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

当我尝试为 Google 开发人员 API 执行请求时。购买()。产品()。 get() 我收到 403 错误:projectNotLinked.

留言告诉我"The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."

这时候我可以去控制台,unlink一个以前的项目,link这个,运行代码,代码可以工作。

但是,我无法永久取消link 以前的项目:我需要将它们都保留linked。我该如何解决这个问题?

我环顾四周,找不到解决办法。试图打电话给Google,他们告诉我他们不支持这种请求。

提前致谢。

Andy 的评论是正确的,我发现 Google Play Developer Console 中的 LINKED PROJECT 描述充其量令人困惑。

但是,我在 Google 开发人员控制台中设置了一个具有适当服务器密钥和服务帐户的公司项目。这并不理想,但它确实有效。然后,您可以在 Google Play Developer Console 中为所需的服务帐户分配权限。

您也可以只设置一个密钥和服务帐户,如果这样可以更简单,并按照下面 PHP 中所示的方式使用它们作为服务器

$service_account_name = 'xxxxxxxxxx-xxxxxxxxxxxxxxx@developer.gserviceaccount.com';
$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";

那么您需要为其他应用程序做的就是更改 $package_name.

$package_name = "com.yourcompany.yourappname2";

然后使用Google服务AndroidPublisher查询订阅

$service = new Google_Service_AndroidPublisher($client);

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

您还可以开始在 Google Play Developer Console 中分配多个密钥、服务帐户和您添加其他项目的其他凭据。

再次强调@andy 的评论:只能有一个链接的API项目

我花了很多时间才弄明白这一点。 Google 的文档在这里没有帮助。

如果您需要访问多个 projects/applications,您必须在单个链接的 API 项目中创建多个服务帐户并单独管理对应用程序的访问。