Google Drive PHP库问题

snz8szmq  于 2023-09-29  发布在  PHP
关注(0)|答案(1)|浏览(144)

我正在创建文件夹内谷歌驱动器与php谷歌驱动器库,目前我设置其权限给任何人,这不是我需要我只想谁是该驱动器的所有者谁给了他的凭证在json文件可以读取或特定的电子邮件,我允许这个chatgpt没有给予任何正确的解决方案,请帮助我重新评级这一点.下面是代码

$driveService = initialize_google_drive_client();
        $folder_name = 'test123';
        // Define the folder metadata
        $folderMetadata = new Google_Service_Drive_DriveFile([
            'name' => $folder_name,
            'mimeType' => 'application/vnd.google-apps.folder',
        ]);
        // Create the folder in Google Drive
        $folder = $driveService->files->create($folderMetadata, [
            'fields' => 'id',
        ]);
        if ($folder) {
            // Set permissions for the folder to make it public
            $permission = new Google_Service_Drive_Permission([
                'type' => 'anyone',
                'role' => 'reader',
            ]);
            $driveService->permissions->create($folder->id, $permission);
        }

chatgpt代码在这里

if ($folder) {
    // Remove any existing permissions for 'anyone' (optional)
    $driveService->permissions->delete($folder->id, 'anyone');
    // Set permissions for specific email addresses
    $emailAddresses = ['[email protected]', '[email protected]'];
    foreach ($emailAddresses as $email) {
        $permission = new Google_Service_Drive_Permission([
            'type' => 'user',
            'role' => 'writer', // You can also use 'reader' or other roles as needed.
            'emailAddress' => $email,
        ]);
        $driveService->permissions->create($folder->id, $permission);
    }
}
bvjveswy

bvjveswy1#

你做错了credentials.json应该是由创建的,开发人员违反了谷歌的TOS来发布你的credentials.json。
credentials.json不与用户链接,它链接到Google开发者控制台上的项目,用于请求用户的授权。
对应用进行身份验证并赠款其访问数据权限的用户是将创建文件的用户,因此您不需要设置这些文件的权限。

相关问题