javascriptgoogle-drive-api

Get an end users list of files in google drive


So i feel like im missing something here. I have been to websites before where i can click a button which opens a popup, authorize my account for google, select a file from google drive, then upload it to the website (or at least it appears this way). Now im looking through documentation and everything i see wants MY api creds. I want to use the end users though.

My goal is to have the end user pick a file from their google drive, get that url, then store it so they can have a link to view it in THEIR drive account in another window. I dont want it in MY drive account so why does it appear i need api creds? It really doesnt need ME to have a drive account at all. Am i searching the wrong stuff here? How can this be done?

To add: This will be for a front-end web app (javascript).


Solution

  • About your question, I think the one that explains the most what you want to accomplish is this documentation here

    The Google Picker is a "File Open" dialog for information stored on Google servers. You can use the Google Picker API to allow users to open or upload Google Drive files.

    Display the Google Picker

    You can also review more information about the Google Picker API here and a code sample here.

    The setOAuthToken function allows an app to use the current auth token to determine which Google Account the Google Picker uses to display the files. If a user is signed in with multiple Google Accounts, the Google Picker can display the files of the appropriate authorized account.

    Since you want to use a web application (users from your website,) you will need to create a GCP project, enable the API for Google Drive & Google Picker API under Library.

    Library

    You can search it like this:

    search API library

    After that, you will need to set up a OAuth consent screen.

    OAuth consent screen

    And set it up as External.

    External

    Create an API key using that project.

    API key

    Also, you will need to authorize credentials for a web application, since you want the users of your website to authorize access to their Google Drive to select the files.

    web app OAuth

    Reference: