当我尝试执行Google开发人员API的请求时。购买()。产品()。get()我收到403错误:projectNotLinked。
该消息告诉我“用于调用Google Play开发者API的项目ID尚未在Google Play开发者控制台中链接”。
此时,我可以转到控制台,取消链接上一个项目,然后链接该项目,运行代码,然后代码就可以工作了。
但是,我不能永久取消先前项目的链接:我需要将它们保持链接。我该如何解决这个问题?
我环顾四周,找不到解决方案。试图打电话给Google,他们告诉我他们不支持这种请求。
提前致谢。
Andy的评论是正确的,我发现Google Play开发者控制台中的LINKED PROJECT描述充其量是令人困惑的。
但是,我在Google Developers Console中使用适当的服务器密钥和服务帐户设置了一个公司项目。这不是理想的方法,但是可以。然后,您可以在Google Play开发者控制台中将权限分配给所需的服务帐户。
您还可以只设置一个密钥和服务帐户(如果这样可以简化操作),并按照下面的PHP所示在服务器上使用它们
$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";
然后,您需要为其他应用程序做的就是更改$ package_name。
$package_name = "com.yourcompany.yourappname2";
然后使用Google Service AndroidPublisher查询订阅
$service = new Google_Service_AndroidPublisher($client);
$results = $service->purchases_subscriptions->get($package_name,$subscriptionId,$token,array());
您还可以开始分配多个密钥,服务帐户和其他凭据,然后在Google Play开发者控制台中添加其他项目。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句