0

Is is possible to give google service-account's access to whole drive instead of just folders? I'm unable to switch to a new directory using google docs API in python. It was possible to jump into a folder and then create the document there using google drive APIs but I want to use docs API only and I can't see any way to jump into another folder.

6
  • Hi, please notice that you are asking many questions here. I'd suggest you to edit your post in order to focus on a single specific issue stackoverflow.com/help/how-to-ask Commented Dec 17, 2021 at 8:31
  • sure, I'll update the question. Commented Dec 17, 2021 at 8:52
  • By jump into another folder you mean moving a file to a different folder? You cannot do this in Docs API, you have to use Drive API for this. May I know why you don't want to use Drive, and just Docs? Commented Dec 17, 2021 at 9:57
  • I'm unable to add any content to my doc when I use Drive API. I didn't get any logic which can do batch update using drive APIs. In docs API, it's simply - result = service.documents().batchUpdate(documentId=DOCUMENT_ID, body={'requests': requests}).execute() Commented Dec 17, 2021 at 11:19
  • Of course, batchUpdate is to be used with Docs API. But for file creation, I'd suggest using Drive API, since you want to add it to a specific folder. Take a look at my answer for more information. Commented Dec 17, 2021 at 11:25

1 Answer 1

1

Is is possible to give google service-account's access to whole drive instead of just folders?

If you have a Workspace domain, I'd suggest granting domain-wide authority to the service account in order to impersonate the regular user's My Drive and access everything they can access. See Delegating domain-wide authority to the service account for more details about how to accomplish this.

If this is not an option for you, you should share all top-level items on the Drive, since there's no direct method to share the full My Drive.

It was possible to jump into a folder and then create the document there using google drive APIs but I want to use docs API only and I can't see any way to jump into another folder.

You need to use Drive API to move files between folders. Docs API cannot be used for that.

Sidenote:

Not sure if you're aware of this, but please notice that, if you create a document via Docs API, you can only create a blank document, since all fields apart from title are ignored in this method (see documents.create). If you want to add text, change other properties, etc., you'll have to use documents.batchUpdate.

I'm mentioning this since I don't know whether that was the reason you wanted to create the document via Docs API.

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

6 Comments

currently, I'm unable to view the document in my drive when I create it using Google doc API's documents.create method since I can't give service account access to whole My Drive using Google doc API. So currently I create a document manually in drive then give it service account access and then use its documentId to insert data in this document. But I don't want to do this, I want to create the doc using API and give it google account access. Also my account is not a Workspace domain.
When I use google drive API, I'm able to create a folder in my drive and then able to create a black document inside it but I'm unable to insert any data inside the document since documents.batchUpdate won't work in drive APIs.
@Ask_Ashu Consider the following workflow: (1) Create the file in your desired folder using Drive API developers.google.com/drive/api/v3/…, (2) Share the file with the service account using Drive API developers.google.com/drive/api/v3/manage-sharing, (3) Grab the file id, (4) Using the file id, call Docs API's documents.batchUpdate to update your file accordingly developers.google.com/docs/api/reference/rest/v1/documents/….
This approach is also not working. let me update the question with what I'm trying right now.
okay, I'll post a new question
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.