Home > Software design >  How we can get permission Id from a google drive api using PHP?
How we can get permission Id from a google drive api using PHP?

Time:02-21

I want a permission Id to update my user permissions of a file in google drive using google drive api with PHP.Can anybody tell me how to fetch the permission Id from response. I went through this https://developers.google.com/drive/api/v2/reference/permissions/update. In this I need permission Id to update my permission but I am unable to get it. Can anybody tell me how i can fetch it programatically using PHP. What exact method is there to get the permission Id.

CodePudding user response:

In order to retrieve the permission ID from the file on Google Drive, you can retrieve it using the method of "Permissions: list" of Drive API.

Sample script 1:

From your provided URL, if you are using Drive API v2, you can use the following script.

$fileId = "###"; // Please set the file ID.

$drive = new Google_Service_Drive($client); // Please use your authorization script.
$res = $drive->permissions->listPermissions($fileId);
$permissions = $res->getItems();
foreach ($permissions as &$p) {
    $id = $p->getId();
    print($id . "\n");
}

Sample script 2:

If you are using Drive API v3, you can use the following script.

$fileId = "###"; // Please set the file ID.

$drive = new Google_Service_Drive($client); // Please use your authorization script.
$res = $drive->permissions->listPermissions($fileId);
$permissions = $res->getPermissions();
foreach ($permissions as &$p) {
    $id = $p->getId();
    print($id . "\n");
}

References:

  • Related