Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

Google docs api - get all the document

Is it possible to get all the documents from google docs using google-docs API?

On the API reference page, I am not able to find API for get all the list of documents

the below api used for get single document using documentId.

GET https://docs.googleapis.com/v1/documents/{documentId}

Reference: https://developers.google.com/docs/api/reference/rest/v1/documents/get

If I forget the document Id, how can get the document? this information not available on the reference api page.

question from:https://stackoverflow.com/questions/65841191/google-docs-api-get-all-the-document

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I believe your goal as follows.

  • You want to retrieve all Google Document files using the method of "documents.get" in Google Docs API.
  • You have no Document IDs of all Google Document files. You are required to retrieve the Document ID.

In order to achieve your goal, I would like to propose to use the following 2 processes.

  1. Retrieve Document IDs of Google Document files.

    • In this case, the method of "Files: list" in Drive API is used. Ref

    • In order to retrieve Google Document files, the search query of mimeType='application/vnd.google-apps.document' and trashed=false is used.

    • The sample curl command is as follows.

        curl 
          'https://www.googleapis.com/drive/v3/files?pageSize=1000&q=mimeType%3D%27application%2Fvnd.google-apps.document%27%20and%20trashed%3Dfalse' 
          --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' 
          --header 'Accept: application/json' 
          --compressed
      
    • When you want to retrieve the Google Document files in the specific folder, please use mimeType='application/vnd.google-apps.document' and trashed=false and '###' in parents as the search query.

    • When above curl command is run, the file list including the file IDs is returned.

    • In this sample, the page size is 1000. When you have more document files, please use pageToken.

  2. Retrieve the data from Google Document files.

    • In this case, the method of "documents.get" in Google Docs API is used.
    • Using the file IDs retrieved by above method, you can retrieve all Google Document files. In the current stage, I think that in this case, it is required to request to the endpoint for each Document ID in a loop.
    • In this case, the endpoint in your question can be used.

References:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...