Php 在谷歌API v2中,为什么会出现错误;用于调用Google Play开发者API的项目id尚未链接;发生

Php 在谷歌API v2中,为什么会出现错误;用于调用Google Play开发者API的项目id尚未链接;发生,php,google-api,google-play,google-api-php-client,Php,Google Api,Google Play,Google Api Php Client,当我使用Google API v2时,为了得到一个,我在进行API调用时得到以下错误: { "error": { "errors": [ { "domain": "androidpublisher", "reason": "projectNotLinked", "message": "The project id used to call the Google Play Developer API has not been linked in the Goog

当我使用Google API v2时,为了得到一个,我在进行API调用时得到以下错误:

{
 "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."
 }
}
然后我研究了这个错误,最后在第页、第页和第页上看到了这些建议。我跟踪并仔细检查了项目链接到那里的方式,但没有任何帮助

这就是我所做的

在Google开发者控制台中:

  • 使用现有项目
  • 转到API&auth>API
  • 确保“Google Play Android开发者API”已打开
  • 已将我的现有凭据用于客户端ID、客户端机密和重定向URI。应用程序类型为“本机应用程序”
  • 还创建了一个API密钥,但没有使用它
  • 在Google Play开发者控制台中:

  • 转到设置>API访问
  • 在linkedproject下,我确保来自googledeveloper控制台的上述项目被链接
  • 在我的PHP脚本中:

    <?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);
    

    嘿,我和你有一个类似的问题,我发现问题是我在验证一个用户没有正确的权限

    首先进入Google Play控制台,进入设置>API访问。确保你有一个链接“GooglePlayAndroid开发者”(听起来你和我都有)

    接下来进入设置>用户帐户和权限,确保用户拥有查看订阅或任何您需要的权限。出于测试目的,只需赋予其所有权利

    然后确保通过Oauth对该用户进行身份验证(即从列表中选择他们的电子邮件),然后获取典型的刷新/访问令牌


    现在对我来说,这真的很痛苦,但这仍然让我沮丧了一天。我希望这能解决您的问题:)

    您的回答对我有帮助-关于刷新代币等有很多建议,但我使用的是服务帐户,觉得这不适用于我。仅仅查看权限就表明我没有“财务”权限,这阻止了我验证GooglePlay应用内购买。谢谢@krtko@DevologyLtd这是否意味着,由于您使用的是服务帐户,您还必须向ouath进行身份验证,并执行所有令牌操作?嗨@Kicking莴苣据我所知,没有oAuth/令牌操作-我只需要添加所需的权限。@DevLogyLTD感谢您的回复。我最终解决了我的问题,这与我授权的方式无关(我使用了在链接我的帐户之前创建的应用内购买)。最后,我不必对access_代币做任何事情。仅使用JWT授权我的服务帐户。