[英]403 : Insufficient Permission while creating an folder in google drive api php
I'm implementing google drive api to implement in my application. 我正在实现Google Drive API,以在我的应用程序中实现。 I did that all code configuration from google-drive-client-php documentation.
我从google-drive-client-php文档进行了所有代码配置。 But I got an this permission error.
但是我遇到了这个权限错误。 Please give me any hint for this:
请给我任何提示:
$client = new Google_Client();
$client->setAuthConfig('client_secrets.json');
$client->setAccessType("offline");
$client->setScopes("https://www.googleapis.com/auth/drive");
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$drive = new Google_Service_Drive($client);
$fileMetaData = new Google_Service_Drive_DriveFile(array(
'name' => 'RootFolder',
'mimeType' => 'application/vnd.google-apps.folder'));
$parentFolder = $drive->files->create($fileMetaData, array(
'fields' => 'id'
));
$permission = new Google_Service_Drive_Permission();
$permission->setValue('me');
$permission->setType('anyone');
$permission->setRole('writer');
$drive->permissions->insert($parentFolder->getId(), $permission);
echo "<pre>";
echo json_encode($parentFolder);
} else {
$redirect_uri = 'https://' . $_SERVER['HTTP_HOST'] . '/callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
Thank u :) 感谢你 :)
so you are requesting ... 所以你要...
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
while you actually might require ... 虽然您实际上可能需要...
$client->addScope(Google_Service_Drive::DRIVE);
for reference, here's the mapping of the API scopes: 供参考,以下是API范围的映射:
/** View and manage the files in your Google Drive. */
const DRIVE = "https://www.googleapis.com/auth/drive";
/** View and manage its own configuration data in your Google Drive. */
const DRIVE_APPDATA = "https://www.googleapis.com/auth/drive.appdata";
/** View and manage Google Drive files and folders that you have opened or created with this app. */
const DRIVE_FILE = "https://www.googleapis.com/auth/drive.file";
/** View and manage metadata of files in your Google Drive. */
const DRIVE_METADATA = "https://www.googleapis.com/auth/drive.metadata";
/** View metadata for files in your Google Drive. */
const DRIVE_METADATA_READONLY = "https://www.googleapis.com/auth/drive.metadata.readonly";
/** View the photos, videos and albums in your Google Photos. */
const DRIVE_PHOTOS_READONLY = "https://www.googleapis.com/auth/drive.photos.readonly";
/** View the files in your Google Drive. */
const DRIVE_READONLY = "https://www.googleapis.com/auth/drive.readonly";
/** Modify your Google Apps Script scripts' behavior. */
const DRIVE_SCRIPTS = "https://www.googleapis.com/auth/drive.scripts";
I got an solution for my problem 我为我的问题找到了解决方案
Remove 去掉
$permission->setValue('me');
$ permission->的setValue( '我');
and change this Permission method to 并将此Permission方法更改为
$drive->permissions->insert($parentFolder->getId(), $permission);
$ drive-> permissions-> insert($ parentFolder-> getId(),$ permission);
To 至
$drive->files->create($fileMetaData, array('fields' => 'id'));
$ drive->文件->创建($ fileMetaData,array('fields'=>'id'));
Here in the google drive api insert an setValue() method is deprecated so it was not work. 在Google驱动器api中,不建议使用setValue()方法,因此该方法无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.