403: Недостаточно прав доступа при создании папки в google drive api Переполнение стека

Я внедряю Google Drive API для реализации в моем приложении. Я сделал все настройки кода из документации google-drive-client-php. Но я получил эту ошибку разрешения. Пожалуйста, дайте мне любую подсказку для этого:

$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));
}

Спасибо 🙂

0

Решение

так что вы просите …

$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);

в то время как вы на самом деле может потребовать …

$client->addScope(Google_Service_Drive::DRIVE);

для справки, вот отображение областей 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";
1

Другие решения

У меня есть решение моей проблемы

Удалить

$ Permission-> SetValue ( ‘я’);

и измените этот метод разрешения на

$ drive-> permissions-> insert ($ parentFolder-> getId (), $missions);

к

$ drive-> files-> create ($ fileMetaData, array (‘fields’ => ‘id’));

Здесь, в Google Drive API вставить метод setValue () устарела, поэтому он не работал.

0