Determining sharing settings of Google Document by link

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:
which is not shared for external people.

Source: stackoverflow-javascript