我已成功将Google PHP API与服务帐户配合使用来操纵Google CloudDNS记录,如下所示:
$permisson = 'https://www.googleapis.com/auth/ndev.clouddns.readwrite';
$client = new Google_Client();
$client->setApplicationName("foo");
$credentials = new Google_Auth_AssertionCredentials(
$googleApiServiceAccount,
array($permission),
file_get_contents($googleApiKeyFile)
);
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($credentials);
}
$accessToken = $client->getAccessToken();
[..]
是否可以使用类似的方案进行Google Apps Spreadsheets访问?什么用作$权限以及我必须在Google Developer Console中启用哪种API?
请注意:我完全清楚通过oAuth2轻松访问API - 我正在寻找通过服务帐户访问API的方法。
答案 0 :(得分:0)
关于许可部分:
$permissions = array(
"https://spreadsheets.google.com/feeds",
"https://docs.google.com/feeds"
);
$credentials = new Google_Auth_AssertionCredentials(
$googleApiServiceAccount,
$permissions,
file_get_contents($googleApiKeyFile)
);
Google API控制台服务帐户需要作为协作者添加到您要访问的电子表格中!你可以创建/看到 这里的服务帐户电子邮件地址:
https://console.developers.google.com/project/YOUR-PROJECT-NAME/permissions/projectpermissions
这是要使用的服务:
$service = new \Google\Spreadsheet\SpreadsheetService();