是否可以通过谷歌API服务帐户访问谷歌电子表格API?如何在PHP中实现这一点?
我正在成功地使用带有服务帐户的Google PHP API来操纵Google CloudDNS记录,如下所示:是否可以通过谷歌API服务帐户访问谷歌电子表格API?如何在PHP中实现这一点?,php,google-api,google-apps,Php,Google Api,Google Apps,我正在成功地使用带有服务帐户的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_AssertionCredential
$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();
[..]
谷歌应用程序电子表格访问是否可以使用类似的方案?作为$permission使用什么?我必须在Google开发者控制台中启用什么样的API
请注意:我完全知道通过oAuth2访问API很容易——我正在寻找通过服务帐户访问API的方法。关于权限部分:
$permissions = array(
"https://spreadsheets.google.com/feeds",
"https://docs.google.com/feeds"
);
$credentials = new Google_Auth_AssertionCredentials(
$googleApiServiceAccount,
$permissions,
file_get_contents($googleApiKeyFile)
);
谷歌API控制台服务帐户需要作为合作者添加到您想要访问的电子表格中!您可以创建/查看
服务帐户的电子邮件地址如下:
这是要使用的服务:
$service = new \Google\Spreadsheet\SpreadsheetService();
关于许可部分:
$permissions = array(
"https://spreadsheets.google.com/feeds",
"https://docs.google.com/feeds"
);
$credentials = new Google_Auth_AssertionCredentials(
$googleApiServiceAccount,
$permissions,
file_get_contents($googleApiKeyFile)
);
谷歌API控制台服务帐户需要作为合作者添加到您想要访问的电子表格中!您可以创建/查看
服务帐户的电子邮件地址如下:
这是要使用的服务:
$service = new \Google\Spreadsheet\SpreadsheetService();
可能的重复可能的重复