Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How we can get permission Id from a google drive api using PHP?

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading