node-google-spreadsheet
node-google-spreadsheet copied to clipboard
Change permissions of a google sheet / newly created sheet.
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",
});
})();
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!
Any updates on this functionality?
Hi, looking for this functionality: Create new Google Spreadsheet, get the URL, make sure it's visible to everyone.
HOW?
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.
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.
- Create 1000's of google sheets and make them all public, get url of all
- Update 1000's of google sheets hourly - price and stock. Need to probably delete all rows, then repopulate with the newer data (whatever works)
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.
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.
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
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