Search code examples
google-sheetsgoogle-docsgoogle-docs-apigoogle-sheets-api

How to distinguish between a Google Doc and Spreadsheet with the URL?


Is it possible to tell if a URL links to Google Sheets, Google Docs, or another Google app from the sharable link?

The app I am working on allows users to share links, but Safari on iOS devices doesn't seem to handle these links very well. To help ease our users pain, we would like to directly open the link in Sheets, Docs, or whatever other Google app works best, should it already be installed. I have been able to accomplish this by editing the link provided, replacing:

https://

with:

googledocs://

or:

googlesheets://

However, based on the sharable links, it's hard to tell if the link is a Google Doc, Google Sheet, or something else all together. I originally thought Google Sheets used sheets.google.com, but after testing out this change, I realized both Sheets and Docs use docs.google.com for their sharable links. If the wrong app is opened, Google Sheets or Docs will throw an error saying it cannot open the file.

Is there a simple way to make this distinction and ensure the appropriate Google app opens for any given sharable link?


Solution

  • Definitely not from the shareable link. The shareable link is basically just a redirect to the actual document. It's a hash that's generated independently from the original document that is intentionally obfuscated to prevent malicious parties from guessing them.

    The only way to know what's on the other side of the link is to visit it or use the Google Drive API to query the document for info.