0

In our application users can submit a link to a Google Document (from Google Drive). We want to be able to check whether the document is shared in a way where anyone with the link can access the document. How is that possible (preferably using Javascript).

Such a link could be: https://docs.google.com/a/peergrade.io/document/d/1_PgKkr7e4E1uEE4O_SHswq4tjBDLthg0KxGXjtIMLio/edit?usp=sharing which is not shared for external people.

Our application is running in the browser. The use-case is that students of our application can hand-in a Google Document that other people have to look at. Some students forget to share their document beforehand, which leads to problems. We want to alert the student that their document is not shared correctly.

We don't need to actually access the document, just figure out if it would be accessible to other people.

Using an API would be perfect, but at this point, we only have the link to the document available.

utdiscant
  • 11,128
  • 8
  • 31
  • 40
  • This needs more info. What kind of application is it, a web app running in the browser? How would you expect to get this information if the document is *not* accessible to others - would your app, which won't be logged in to Google Docs and even if it were, presumably not with the user's credentials - not be denied access if it is? (And come to think of it, would that alone not be proof enough that it isn't accessible)? – Pekka Feb 17 '17 at 10:07
  • Also, Google might change the implementation after a few days, so you cannot rely on string. Check should be if google drive exposes some API to do this instead of this question. – Akshay Khandelwal Feb 17 '17 at 10:11
  • Thanks for the questions. I will update the question. – utdiscant Feb 17 '17 at 10:18

1 Answers1

2

you can get file metadata using following request

GET https://www.googleapis.com/drive/v3/files/{FILE_ID}?fields=id%2Ckind%2CmimeType%2Cname%2Cshared&key={YOUR_API_KEY}

note the shared tag in the request

which will give you something like

{


 "kind": "drive#file",
 "id": "bla_bla_gibberish_id",
 "name": "Sample File",
 "mimeType": "application/vnd.google-apps.spreadsheet",
 "shared": true
}

Now, to get fileID from a link:

function getIdFromUrl(url) { return url.match(/[-\w]{25,}/); }

as posted here

Community
  • 1
  • 1
xGeo
  • 2,149
  • 2
  • 18
  • 39