Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created September 14, 2020 02:02
Show Gist options
  • Save tanaikech/d3ce0c2186885ee27d23e02ddd2696b7 to your computer and use it in GitHub Desktop.
Save tanaikech/d3ce0c2186885ee27d23e02ddd2696b7 to your computer and use it in GitHub Desktop.
Retrieving All URLs in Google Document using Google Apps Script

Retrieving All URLs in Google Document using Google Apps Script

This is a sample script for retrieving All URLs in Google Document using Google Apps Script. In this sample script, the method of "documents.get" in Google Docs API is used. By this, the URL can be retrieve using JSON.parse().

Sample script

Before you use this script, please enable Google Docs API at Advanced Google Services.

const documentId = "###"; // Please set the Google Document ID.

const content = Docs.Documents.get(documentId).body.content;
const urls = [];
JSON.parse(JSON.stringify(content), (k, v) => {
  if (k == "url") urls.push(v);
});
console.log(urls);

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment