Pez*_*zze 6 google-api google-play-services
当我尝试执行Google开发人员API的请求时.购买().产品(5).get()我收到403错误:projectNotLinked.
该消息告诉我"用于调用Google Play Developer API的项目ID尚未在Google Play开发者控制台中链接."
此时,我可以转到控制台,取消链接以前的项目,并链接这个,运行代码,代码工作.
但是,我不能永久地取消上一个项目的链接:我需要将它们保持联系.我该如何解决这个问题?
我环顾四周,无法找到解决方案.试图打电话给谷歌,他们告诉我他们不支持这种请求.
提前致谢.
Andy 的评论是正确的,我发现 Google Play Developer Console 中的 LINKED PROJECT 描述充其量令人困惑。
但是,我在 Google Developers Console 中设置了一个具有适当服务器密钥和服务帐户的公司项目。这并不理想,但它有效。然后,您可以在 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";
Run Code Online (Sandbox Code Playgroud)
然后您需要为其他应用程序做的就是更改 $package_name。
$package_name = "com.yourcompany.yourappname2";
Run Code Online (Sandbox Code Playgroud)
然后使用谷歌服务 AndroidPublisher 查询订阅
$service = new Google_Service_AndroidPublisher($client);
$results = $service->purchases_subscriptions->get($package_name,$subscriptionId,$token,array());
Run Code Online (Sandbox Code Playgroud)
您还可以开始分配多个密钥、服务帐户和您在 Google Play 开发者控制台中添加其他项目的其他凭据。
重新强调@ andy的评论:只能有一个链接的API项目.
我花了很长时间才发现这一点.Google的文档在这里没有帮助.
如果您需要访问多个项目/应用程序,则必须在单个链接的API项目中创建多个服务帐户,并单独管理对应用程序的访问.
归档时间: |
|
查看次数: |
2135 次 |
最近记录: |