Edits history of script submission #23319 for ' List Comments (gdocs)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Comments
     * List the comments on a Google Doc (or any Drive file), each with its author, content, quoted text, `resolved` state and replies. Pass the returned `nextPageToken` as `page_token` for the next page. Requires drive.readonly or drive on the connection (the documents scope doesn't cover the Drive comments API).
     */
    export async function main(
      auth: RT.Gdocs,
      document_id: string,
      include_deleted: boolean = false,
      page_size: number = 100,
      page_token: string | undefined
    ) {
      const url = new URL(
        `https://www.googleapis.com/drive/v3/files/${document_id}/comments`
      )
      // The comments API rejects requests without a field mask.
      url.searchParams.append("fields", "comments,nextPageToken")
      url.searchParams.append("includeDeleted", String(!!include_deleted))
      url.searchParams.append("pageSize", String(page_size || 100))
      if (page_token != null && page_token !== "")
        url.searchParams.append("pageToken", page_token)
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago