这个问题正在推动我的转弯 - 我已经按照此页面上的说明创建了一个谷歌服务帐户
https://developers.google.com/shopping-content/v2/quickstart
我有我的 .json 文件
我已经从 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);
我替换 ***** 的地方是我的商家 ID。
无论我尝试什么,我都无法连接并收到以下错误。
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
)
这是我最后的手段。我为域范围的委派设置了帐户。
有什么帮助吗?
乔恩