【发布时间】:2019-04-24 03:16:20
【问题描述】:
你能帮我解决这个问题吗?
我正在使用 PHP GOOGLE API V2.2.2
我的代码使用为其创建的 gserviceaccount 工作,但是,当我尝试在我的个人 GOOGLE DRIVE 上操作文件时,我遇到了这个错误...
我尝试按照此处显示的步骤操作:Github issue 801
一切顺利,我的项目显示在我的authorized client list
这是我在我的谷歌驱动器中创建文件夹的代码:
function NovaPasta() {
require_once APPPATH . 'third_party/google-api-php-client-2.2.2/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS='. APPPATH . 'third_party/google-api-php-client-2.2.2/Asist-428f3540df9a.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
//$client->setAuthConfig(APPPATH . 'third_party/google-api-php-client-2.2.2/Asist-428f3540df9a.json');
$client->addScope("https://www.googleapis.com/auth/drive");
$client->setSubject('xxxx@gmail.com');
$driveService = new Google_Service_Drive($client);
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'new folder name',
'mimeType' => 'application/vnd.google-apps.folder'));
$file = $driveService->files->create($fileMetadata, array(
'fields' => 'id'));
printf("Folder ID: %s\n", $file->id);
}
这是错误:
遇到未捕获的异常 类型:Google_Service_Exception
消息:{“error”:“unauthorized_client”,“error_description”:“客户端未授权使用此方法检索访问令牌,或者客户端未授权任何请求的范围。” }
【问题讨论】:
-
您是否仅尝试访问您的驱动器帐户?除了您自己的帐户之外,您永远不会访问其他用户帐户吗?
-
你能告诉我们你用过什么范围吗?
标签: php google-api google-drive-api google-api-php-client