Siddharth Sogani
Siddharth Sogani

Reputation: 123

Unable to access sheet created through service account by Google spreadsheet API

Hi I created a spreadsheet using google spreadsheet API with service account credentials (using service token).The problem is that sheet got created in the service account which I cannot access. So how can I make the sheet public? Is there any way to make a sheet public using its URL? Thanks

Upvotes: 1

Views: 703

Answers (1)

ReyAnthonyRenacia
ReyAnthonyRenacia

Reputation: 17651

For managing permissions of your drive files (spreadsheet, docs, etc), you'll be using Permissions.create where you'll set the type to "anyone". You can check thos SO post for code implementation sample.

private Permission insertPermission(Drive service, String fileId) throws Exception{
   Permission newPermission = new Permission();
   newPermission.setType("anyone");
   newPermission.setRole("reader");
   newPermission.setValue("");
   newPermission.setWithLink(true);
   return service.permissions().insert(fileId, newPermission).execute();
}

Upvotes: 1

Related Questions