Search code examples
apigoogle-docsgoogle-appsgoogle-docs-api

Is possible to know the permission in a folder in google docs api


I just want to know if is possible to get the permission that a user has in a folder or shared folder,

am getting the folders with this url

  "https://docs.google.com/feeds/default/private/full/-/folder"

but how can i get the permission of the folders whit the DocumentListEntry entry object ?

this is my code:

                 query = new DocumentQuery(new URL(
        "https://docs.google.com/feeds/default/private/full/-/folder"));

                    feed = client.getFeed(query, DocumentListFeed.class);
        // Create a new list of tags with the values of google docs
        for (DocumentListEntry entry : feed.getEntries()) {
                    entry.getCanEdit() // this always return true even if i don't have permission in the folder

                    }

i hope some one han help me, thanks in advance.


Solution

  • In the DocsList API, you have the class Folder which has the following methods: getEditors(), getOwners(), getViewers(); each of them returns an array of users.

    Now I don't think you can get the actual folder object by URL, but you could use the: getFolderById() method.

    Here is a simple example:

    1. First you need to find out what's the ID of the folder, there are at least three ways, but the simplest is to click on the actual folder in Google Docs and analyze it's URL:

      https://docs.google.com/a/appsbroker.com/?tab=mo#folders/0B7_GXypCeAAdYmM1ZjJjYzktMWM1OS00ZDBiLTk5MDQtNjhiY2U4Zjc2YjZk

      In the example above, the folder Id is:

      0B7_GXypCeAAdYmM1ZjJjYzktMWM1OS00ZDBiLTk5MDQtNjhiY2U4Zjc2YjZk

    2. After that you can write a simple script:

      function myFunction() {
          //replace ... with your folder id
          var folder = DocsList.getFolderById("...");
          var owner = folder.getOwner();
          var editors = folder.getEditors();
          var viewers = folder.getViewers();
          //add code to go through the arrays and display them
      }