且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用PHP运行Google Embed API服务器端授权?

更新时间:2023-11-27 22:13:58

这是我最终完成此操作的方式

here is how I ended up doing this

$scope = 'https://www.googleapis.com/auth/analytics.readonly';
$jsonKey = json_decode('[json file content here]', true);
// OR json key file path
// $jsonKeyFilePath = '/full/path/to/service-account.json';

$client = new \Google_Client();
$client->setScopes([$scope]);
$client->setAuthConfig($jsonKey);

// OR use json file
// $client->setAuthConfigFile($jsonKeyFilePath);

$client->useApplicationDefaultCredentials();
$client->fetchAccessTokenWithAssertion();

echo $client->getAccessToken();

在Google api客户端v2中有一些更新 https://github.com/google/google-api -php-client/blob/master/UPGRADING.md

In google api client v2 there were some updates https://github.com/google/google-api-php-client/blob/master/UPGRADING.md

截至2016年9月,文档中尚未更新(其中包含v1的howto) https://developers.google.com/api-client-library /php/auth/service-accounts

that as of Sep 2016 are not yet updated in the docs (which contains howto for v1) https://developers.google.com/api-client-library/php/auth/service-accounts