[英]Google API Server to server authentication PHP
This problem is driving my round the bend - i have created a google service account as per the instructions on this page 这个问题使我转弯-根据此页面上的说明,我已经创建了一个Google服务帐户
https://developers.google.com/shopping-content/v2/quickstart https://developers.google.com/shopping-content/v2/quickstart
and i have my .json file 我有我的.json文件
I have download the google api library from git and written the following PHP 我已经从git下载了google api库,并编写了以下PHP
require_once 'vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=content-api-key.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/content');
$httpClient = $client->authorize();
$response = $httpClient->get('https://www.googleapis.com/content/v2/********/accounts');
print_r($response);
Where i replace ***** is my merchant id. 我替换*****的位置是我的商人ID。
How no matter what i try i can't connect and get the following error. 无论我怎么尝试,我都无法连接并出现以下错误。
GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => Unauthorized
[statusCode:GuzzleHttp\Psr7\Response:private] => 401
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Vary] => Array
(
[0] => X-Origin
[1] => Origin,Accept-Encoding
)
[WWW-Authenticate] => Array
(
[0] => Bearer realm="https://accounts.google.com/", error=invalid_token
)
This is my last resort. 这是我的不得已。 I have the account set-up for domain wide delegation.
我有用于域范围委派的帐户设置。
Any help? 有什么帮助吗?
Jon 乔恩
Unauthorized
未经授权
Means that the account that you are authenticating with does not have access to do what you are trying to do. 意味着您要进行身份验证的帐户无权执行您尝试执行的操作。
Service account 服务帐号
What you need to remember is that a service account is not you. 您需要记住的是,服务帐户不是您。 It is also not the account that created it on the developer console.
也不是在开发者控制台上创建它的帐户。 A service account a dummy user it has its on drive account calendar account and you can share it access with your
Merchant Account
服务帐户是虚拟用户,具有其在驱动器帐户日历帐户,您可以将其与您的
Merchant Account
共享访问权限
Service account perauthorization 服务帐户授权
Make sure that you have followed Service accounts to set up your service accounts access. 确保已遵循服务帐户来设置服务帐户访问权限。
In the Merchant account add a new user take the service account email address and add that.
在商家帐户中添加一个新用户,获取服务帐户的电子邮件地址并添加。
- Add the new service account as a user to your Merchant Center account.
将新服务帐户作为用户添加到您的Merchant Center帐户。 If you are a third party developer, you will need to have your client do this step for you.
如果您是第三方开发人员,则需要让您的客户为您执行此步骤。
- Go to your Merchant Center account.
转到您的Merchant Center帐户。
- Go to the 'Users' list in the settings of your Merchant Center account.
转到Merchant Center帐户设置中的“用户”列表。
- Click the + button, and use the service account ID as the email address for the new user.
单击+按钮,然后使用服务帐户ID作为新用户的电子邮件地址。
- If you did not take note of the service account ID earlier, go to the Service Accounts administration page and select the project you created.
如果您之前没有记下服务帐户ID,请转到“服务帐户”管理页面并选择您创建的项目。
- Specify User access and Email notifications, note that use of the Accounts service requires Admin access.
指定用户访问权限和电子邮件通知,请注意,使用帐户服务需要管理员访问权限。 Add service account user page screenshot.
添加服务帐户用户页面截图。
- Click on the blue box to the left of Cancel.
单击取消左侧的蓝色框。 You will be returned to the list of users, and the service account ID should be listed with the chosen user role(s).
您将返回到用户列表,并且服务帐户ID应与所选的用户角色一起列出。
- Repeat the process for all other service accounts you want to add.
对您要添加的所有其他服务帐户重复该过程。
- View existing service account users by going to the Users tab.
通过转到“用户”选项卡查看现有服务帐户的用户。 These will be users with an email address ending in 'gserviceaccount.com'.
这些用户的电子邮件地址以“ gserviceaccount.com”结尾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.