Search code examples
javascriptgoogle-apigoogle-drive-apigoogle-api-js-client

getIdForEmail() not a function in Google Drive API Permissions


I need to change the permission of every uploaded file. But when I try to add this code,

printPermissionIdForEmail(email) {
var request = gapi.client.drive.permissions.getIdForEmail({
  'email': email,
});
request.execute(function(resp) {
  return ('ID: ' + resp.id);
});

}

I got an error of getIdForEmail is not a function.

gapi.client.init, gapi.auth2.getAuthInstance(), 

are working. But why gapi.client.drive.permissions.getIdForEmail is not working? There is something I need to do? in Google Developers Page? in my Code?


Solution

  • getIdForEmail is a method only available in Google Drive v2.

    With V3 you are going to have to go after it in another manner.

    Do a files.list with the q parameter. In the q parameter supply the user whos permissions you wish to change. You can see here how to use search This would find all the files where someuser is the owner.

    'someuser@gmail.com' in owners

    Then you will get a list of file resources you can then check the permissions on each file using permissions.list and use that to change the ones you need.

    I am not a JavaScript developer but I found this in the documentation it shows how to use search to list files.

      /**
       * Print files.
       */
      function listFiles() {
        gapi.client.drive.files.list({
          'q': "'someuser@gmail.com' in owners",
          'fields': "*"
        }).then(function(response) {
          appendPre('Files:');
          var files = response.result.files;
          if (files && files.length > 0) {
            for (var i = 0; i < files.length; i++) {
              var file = files[i];
              appendPre(file.name + ' (' + file.id + ')');
            }
          } else {
            appendPre('No files found.');
          }
        });
      }
    

    Update:

    I just spotted this. About.get Gets information about the user, the user's Drive, and system capabilities

    {
     "user": {
      "kind": "drive#user",
      "displayName": "Linda Lawton",
      "photoLink": "xxxx",
      "me": true,
      "permissionId": "060305882255734372",
      "emailAddress": "xxxx@gmail.com"
     }
    }
    

    Could that be the same permissionId you were looking for?