本文介绍了在Google API v2中,为什么错误“用于调用Google Play开发者API的项目ID尚未链接”发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Google API v2时,要获取,我在进行API调用时遇到以下错误:

  {
error:{
errors:[
{
domain:androidpublisher,
reason:projectNotLinked,
message :用于调用Google Play开发者API的项目ID尚未在Google Play开发者控制台中关联。
}
],
code:403,
message:用于调用Google Play Developer API的项目ID尚未与Google Play Developer链接安慰。
}
}

然后我研究了这个错误,并最终看到了建议在页面上,页面,以及页面。我跟随并仔细检查了项目链接的方式,但没有帮助。



这就是我所做的......



在Google开发者控制台中:


  1. 使用现有项目。

  2. 去API和& auth> API。

  3. 确保Google Play Android开发人员API处于开启状态。

  4. 使用我的现有证书作为客户端ID,CLIENT SECRET和重新选择URIS。应用程序类型是原生应用程序。

  5. 创建了一个API KEY,但未使用它。

在Google Play开发者控制台中:


  1. 进入设置> API访问。 >在LINKED PROJECT下,我确保将以上项目与Google Developer Console相关联。

在我的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访问。请确保您有一个关联的Google Play Android开发人员(听起来就像您和我一样)。



接下来进入设置>用户帐户和权利,请确保用户拥有查看订阅的适当权限或任何您需要的权限。出于测试的目的,只需赋予它所有的权利。然后确保通过Oauth验证此用户(即从列表中选择他们的电子邮件),然后获得典型的刷新/访问令牌

p>

现在对我来说确实显得非常痛苦,但仍需要一整天的时间。我希望这可以解决您的问题:)


When I'm using Google API v2, to get an inapp listing, I'm getting the following error when I'm making the API call:

{
 "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."
 }
}

I then researched this error and ended up seeing the suggestions on this page, this page, and on this page as well. I followed and double-checked the way the projects get linked there but it did not help.

This is what I did...

In Google Developer Console:

  1. Used an existing project.
  2. Went to APIs & auth > APIs.
  3. Ensured "Google Play Android Developer API" was turned ON.
  4. Used my existing credentials for CLIENT ID, CLIENT SECRET, and REDIRECT URIS. Application type was "native application".
  5. Created an API KEY as well, but did not use it.

In Google Play Developer Console:

  1. Went to SETTINGS > API access.
  2. Under LINKED PROJECT, I ensured the above project from the Google Developer Console was linked.

In my PHP script:

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

Which led to the above error.

Any other suggestions to resolve this error with using refresh tokens?

解决方案

Hey I was having a similar issue as you, I figured out the problem was I was the authenticating a user did not have the right permissions.

First go into your Google Play Console, go under Settings> API Access. Make sure that you have a linked "Google Play Android Developer" (which is sounds like you do and I did as well).

Next go into Settings>User Accounts and Rights, make sure the user has the proper rights to view subscriptions or whatever you need it to. For testing purposes just give it all the rights.

Then make sure to Authenticate this user via Oauth(ie select their email from the list) and then get typical refresh/access token

Really seems so painfully obvious to me now, but it still took a day of frustration. I hope this solves your issue :)

这篇关于在Google API v2中,为什么错误“用于调用Google Play开发者API的项目ID尚未链接”发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:39