This article explains how to access Google Drive files through Google Drive API v3 and using OAuth2. The interface assets introduced below were created using API Explorer and do not require any programming.
The first three steps enable to you retrieve four values you will need to run the sample experience available at the bottom of this article:
- Client ID
- Client Secret
- Refresh Token
- Folder ID
Credit: The method described here is based on this solution published on Stack Overflow.
Step 1: Create a Google App to grant access to your Drive.
This first step enables you to create a "Google app" that will be granted the right to access files stored in your Google Drive folder. This will give you a Client ID and Client Secret for use in Step 2
If you already have an app and a Client ID / Client Secret, you can go directly to Step 2.
- Create a Google Account (eg. email@example.com) - or skip this step if you are using an existing account.
- Use the Google API console to create a new project.
- If you don't have a project yet, click the Create button or select the menu item Select a project -> New Project.
- Give your project a name, for ex: APIForIntuiface and click on CREATE
- Select your project and select the project you just created.
- Create a new set of credentials for your project.
- Click Credentials in the left hand navigation bar and then choose the "Create credentials" button in the pop-up
- Select OAuth client ID
- If you're asked to "set a product name on the consent screen", follow the instructions and select "Internal" or "External", depending on your needs, then restart the credentialing process
- Select Web application for the "Application Type"
- Under Authorized redirect URIs, add
- Click on Create
- Copy the Client ID and Client Secret that appear on screen.
Step 2: Generate a Refresh Token to be used in your Intuiface experience.
This step assumes you have already registered a Google App and your Client ID & Client Secret are ready to be used.
Here is how to retrieve your Refresh Token:
- Go to Oauth2 playground: https://developers.google.com/oauthplayground
- In Settings (gear icon), set
- Oauth flow: "Server-side"
- Access type: Offline
- Use your own OAuth credentials: Select this option.
- Client ID and Client Secret: Enter the information you created in Step 1.
- Click the Close button
- On the left side of the screen, under Step 1, expand the item "Drive API v3" and select the URL https://www.googleapis.com/auth/drive (having said that, this technique also works for any of the Google APIs listed)
- Click Authorize APIs. You will be prompted to choose your Google account and confirm access
- On the left side of the screen, under Step 2, click the button "Exchange Authorization code for tokens"
- Copy the returned Refresh Token.
Step 3: Find your Drive Folder ID
Last, you need to find the ID of the folder you want to use in your experience. To find this Folder ID, while logged into the same account used in the Steps 1 & 2, use your web browser to go to https://drive.google.com/ and navigate to the appropriate folder.
In your browser's navigation bar, the Folder ID is composed of all the character after the last slash '/'. Copy this value for the last step.
IMPORTANT NOTE: In the experience shared in Step 4 below, the Folder ID global variable must contain the following text, where FOLDER_ID is the ID you pulled from your browser's navigation bar:
'FOLDER_ID' in parents
This "formula" is used as a query parameter for the Drive API to only look for files that have this folder ID as a parent.
Step 4: Download sample experience and enter your credentials
Click this link to download the Intuiface experience sample.
Once the experience is open in your Composer, you need to fill in the values for the following Global Variables:
- Client ID, Client Secret and Refresh Token have to be written exactly as found in Steps 1 & 2.
- Folder ID has to be written between single quotes followed by "in parents", such as
'abc123def456' in parents
Once you have entered the 4 values, save the project and go in Play Mode to test it.
How it works
Explanations about the 2 interface assets used in the sample above will be added later in this section.