node-google-spreadsheet icon indicating copy to clipboard operation
node-google-spreadsheet copied to clipboard

Change permissions of a google sheet / newly created sheet.

Open vaibhavgeek opened this issue 4 years ago • 2 comments

Permissions are scope of google drive in googleapis and not sheets but it would be cool to have that integrated with this implementation of spreadsheet.

My usecase : I would like to make a sheet public and get the new url.

This is how I do it right now.

let { google } = require('googleapis');
var creds = require('./google-creds.json');
(async function main() {
  const jwtClient = new google.auth.JWT(
    creds.client_email,
    null,
    creds.private_key,
    ['https://www.googleapis.com/auth/drive'],
    null
  );
  
  drive = google.drive({ version: "v3", auth: jwtClient });
   const res = await drive.permissions.create({
    resource: {
      type: "anyone",
      role: "writer"  // Please set the email address you want to give the permission.
    },
    fileId: doc.spreadsheetId,
    fields: "id",
  });
})();

vaibhavgeek avatar Jan 17 '21 08:01 vaibhavgeek

I'd love to have some basic Drive api functionality built into this module as well, but I have not had the time to implement it. Open to PRs!

theoephraim avatar Jan 20 '21 00:01 theoephraim

Any updates on this functionality?

eugene-b360 avatar May 17 '22 14:05 eugene-b360

Hi, looking for this functionality: Create new Google Spreadsheet, get the URL, make sure it's visible to everyone.

HOW?

doverradio avatar Dec 10 '22 21:12 doverradio

Creating new sheets is supported, but adjusting permissions unfortunately is not.

However, I am working on a bigger rewrite and sharing / permissions is implemented. Just not quite ready for release just yet. Hopefully soon!

In the meantime, you could create the sheet using this module, and then make calls to the drive API directly to adjust the permissions. It's not too bad to implement.

theoephraim avatar Dec 10 '22 22:12 theoephraim

Well, I'm trying to use this to update product inventory on Facebook Shops. Have a large userbase. Thinking of using your library to support it. However, after creating a new sheet successfully just now, I cannot access it despite being logged in as the paid Google Workplace account I have. Is there currently a way I can dump rows of items into a new sheet and make that a publicly accessible url? That's exactly my current use case and need.

  1. Create 1000's of google sheets and make them all public, get url of all
  2. Update 1000's of google sheets hourly - price and stock. Need to probably delete all rows, then repopulate with the newer data (whatever works)

doverradio avatar Dec 10 '22 22:12 doverradio

Assuming you are using service account auth, the sheet will be owned by the service account, and you are not able to log in as that user. You can however enable "domain wide delegation" for your service account, and then impersonate a specific user on your domain. So in that scenario you are still using service account auth but it is as if you are logged in as the user you are impersonating.

Alternatively, you could create the sheet using this module as the service account, and then make a drive API request to update the permissions.

theoephraim avatar Dec 10 '22 22:12 theoephraim

then make a drive API request to update the permissions

Yes, this must be the solution. Can your library handle this part? If no, what would you suggest? It already created one spreadsheet so I would need to successfully change permissions on that, then I am finished.

doverradio avatar Dec 10 '22 22:12 doverradio

Not currently. You will have to make the request to the drive API yourself. Either via an http request, or using google's official npm module.

I just pushed up my wip on the rewrite which has this functionality. Look here

theoephraim avatar Dec 10 '22 22:12 theoephraim

I just pushed a new breaking version that adds a ton of functionality and this sharing stuff is now supported.

Please check it out and let me know if you run into any issues.

https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet?id=sharing-permissions

theoephraim avatar Jun 26 '23 17:06 theoephraim