Jonah Braun
Jonah Braun

Reputation: 4365

Access a Google Doc via API with a shared URL (AuthKey)?

Google Docs allows you to share a document with just the URL. The URL contains a key and authkey to identify the document and authorize access. This allows anonymous access to anyone who has the key.

I would like to access this type of shared document within an application. I've looked at the APIs, and haven't seen anything yet. It seems like this should be possible - since you can access such a document anonymously with a browser, why shouldn't an application be able to access the same document? Anyone know if/how this can be done?

Upvotes: 5

Views: 6367

Answers (3)

Benjamin Conant
Benjamin Conant

Reputation: 1734

Update for anyone who lands here in 2017+ (as I did). Google seems to have changed the way that share links look. They now look like this when you click get shareable link.

https://docs.google.com/spreadsheets/d/[idwillbehere]/edit#gid=0

You can download the the spreadsheet with this curl command. Make sure the sheet is set so that anyone with the link can access it.

curl -o /path/to/file/you/want/csv/to/go.csv 'https://docs.google.com/spreadsheet/ccc?key=[the-id-of-your-spreadsheet]&output=csv' -L

the -L is the trick here has google often moves the csv around but will send you a redirect link. -L tells curl to follow the redirects until it lands on the file.

Upvotes: 4

Hanxue
Hanxue

Reputation: 12756

You can use a simple URL to access the document, in this format:

https://docs.google.com/feeds/download/<type>/Export?docID=<document_ID>&exportFormat=<format>

Type could be any of these - documents - spreadsheets - drawings - presentations

Format could be any of these

  • html
  • txt
  • rtf
  • doc
  • odt
  • xls
  • ods
  • jpeg
  • png
  • svg
  • ppt

For more details, please refer to the Google Drive API at https://developers.google.com/drive/manage-downloads

Here is an example of a URL to export a Google Presentation as PDF

https://docs.google.com/feeds/download/presentations/Export?docID=15HI6KUtc7dm1jZuk1JY022wxWMcYzz3CiC0dxokokak&exportFormat=pdf

Upvotes: 2

Trung
Trung

Reputation: 1032

Some info may help:

When sharing a doc with the link, the URL look like: https://docs.google.com/document/d/xxxxx/edit?hl=en&authkey=yyyyy

To get a copy of the document from curl/wget, use the URL like https://docs.google.com/document/d/xxxxx/export?hl=en&authkey=yyyyy&exportFormat=pdf

See http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#DownloadingDocs for Exporting document.

Upvotes: 2

Related Questions