1

Hello my fellow Programmers, I am working on a java program that automatically creates a Google Spreadsheet with a predefined structure. It works like a charm, but I have a problem with giving writing permissions to other people. I have a list of gmail accounts that should be allowed to write on my spreadsheet, but i can't seem to find a way to give these permissions automatically. I tried to follow these google guides here: https://developers.google.com/drive/api/v2/reference/permissions/insert https://developers.google.com/drive/api/v3/manage-sharing

but it does not work, because I don't have a DriveService running, I'm using a SheetService, and the code from above is not compatible with my SheetService.

The google SheetsService does not have a Permission import like a DriveService does:

no Permission to be imported here

So if somebody has any idea how I can solve this issue I would be very thankful. If you need more information just ask. Thank you.

1 Answer 1

1

The Google drive api and the google sheets api are two diffrent apis.

Google Drive api is a file store api. It just has control over the files themselves. It cant actually edit them.

Google sheets api gives you access to edit the contents of a sheet.

To do this you are going to need two services one a SheetService for editing the sheet itself the other a DriveService for adding the permissions to the sheet.

Drive driveservice = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT)) .setApplicationName(APPLICATION_NAME) .build(); 

driveservice has the permissions methods you need.

Sheets sheetsservice = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT)) .setApplicationName(APPLICATION_NAME) .build(); 

sheetsservice has the permissions methods you need to access sheets.

Just check the scope and make sure you have enough scopes to do what you need on drive as well as on sheets.

Permissions needs

Sign up to request clarification or add additional context in comments.

6 Comments

I would argue that controlling the bytes content of (non-Google) files is a way of editing them ;)
@tehhowch i would argue that is a crazy idea that i have never tried. Now i have to try it.
it seems like I still have a problem with the permissions, I have tried different scopes but everytime it said Insufficient Permission, right now I'm using DriveScopes.DRIVE, DriveScopes.DRIVE_FILE, SheetsScopes.SPREADSHEETS
DriveScopes.DRIVE should give you access to drive and sheets just remember that you will need to reauthorize your user in order to pick up the new scopes
@TGenc if you are changing your application's scopes, you need to remove any saved user access/refresh tokens since they are not generally valid for the new scopes.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.