google 驱动器 api PHP 的 403 权限被拒绝
403 permission denied for google drive api PHP
我在验证日历 API 和 google 驱动器 API 时遇到问题。我有日历 API 工作,我想向它添加 google 驱动器附件功能,但无法让它工作。它给了我这个错误
发生错误:调用 GET https://www.googleapis.com/drive/v2/files 时出错:(403) 权限不足
这是我的代码:
define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->addScope("https://www.googleapis.com/auth/drive");
$client->addScope("https://www.googleapis.com/auth/calendar");
$googleService = new Google_Service_Calendar($client);
$drive_service = new Google_Service_Drive($client);*/
define('SCOPES', implode(' ', array(
Google_Service_Drive::DRIVE_METADATA_READONLY)
));
// Setup the Google Calendar class
$googleClient = new Google_Client();
$googleClient->setApplicationName('test');
$googleClient->setScopes(SCOPES);
$googleClient->addScope("https://www.googleapis.com/auth/drive");
$googleClient->addScope("https://www.googleapis.com/auth/Calendar");
$googleClient->setAuthConfigFile(CLIENT_SECRET_PATH);
$googleService = new Google_Service_Calendar($googleClient);
$driveService = new Google_Service_Drive($googleClient);
我不知道为什么日历可以工作而 google 驱动器不能,而且我很确定 CLIENT_SECRET_PATH 中的身份验证适用于 google 驱动器。
已修复。我在此之前验证了 google 服务,但没有 google 驱动器 api 范围,显然验证不会覆盖。
我在验证日历 API 和 google 驱动器 API 时遇到问题。我有日历 API 工作,我想向它添加 google 驱动器附件功能,但无法让它工作。它给了我这个错误 发生错误:调用 GET https://www.googleapis.com/drive/v2/files 时出错:(403) 权限不足
这是我的代码:
define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->addScope("https://www.googleapis.com/auth/drive");
$client->addScope("https://www.googleapis.com/auth/calendar");
$googleService = new Google_Service_Calendar($client);
$drive_service = new Google_Service_Drive($client);*/
define('SCOPES', implode(' ', array(
Google_Service_Drive::DRIVE_METADATA_READONLY)
));
// Setup the Google Calendar class
$googleClient = new Google_Client();
$googleClient->setApplicationName('test');
$googleClient->setScopes(SCOPES);
$googleClient->addScope("https://www.googleapis.com/auth/drive");
$googleClient->addScope("https://www.googleapis.com/auth/Calendar");
$googleClient->setAuthConfigFile(CLIENT_SECRET_PATH);
$googleService = new Google_Service_Calendar($googleClient);
$driveService = new Google_Service_Drive($googleClient);
我不知道为什么日历可以工作而 google 驱动器不能,而且我很确定 CLIENT_SECRET_PATH 中的身份验证适用于 google 驱动器。
已修复。我在此之前验证了 google 服务,但没有 google 驱动器 api 范围,显然验证不会覆盖。