我已经编写了一个 PHP 项目来更新 Google 电子表格,而目前,我正在使用代码
require_once __DIR__ . '/vendor/autoload.php';
define('APPLICATION_NAME', 'Google Sheets API PHP Quickstart');
define('CREDENTIALS_PATH', '~/.credentials/sheets.googleapis.com-php-quickstart.json');
define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/sheets.googleapis.com-php-quickstart.json
define('SCOPES', implode(' ', array(
Google_Service_Sheets::SPREADSHEETS)
));
但是我找不到凭据的存储位置,因此当我更改帐户时,我遇到一个问题是“来电者没有权限”,我认为它仍在使用旧凭据。谁能告诉我在哪里可以找到它?
谢谢
基于此PHP 快速入门示例,saved credentials
保存在$credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
// Load previously authorized credentials from a file.
$credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
if (file_exists($credentialsPath)) {
$accessToken = json_decode(file_get_contents($credentialsPath), true);
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.
if(!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, json_encode($accessToken));
printf("Credentials saved to %s\n", $credentialsPath);
}
$client->setAccessToken($accessToken);
您可以查看此文档以获取更多信息:Using OAuth 2.0 for Web Server Applications
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句