<<

How To Integrate the Drive API in Denodo

Revision 20200810

NOTE This document is confidential and proprietary of Denodo Technologies. No part of this document may be reproduced in any form by any means without prior written authorization of Denodo Technologies.

Copyright © 2021 Denodo Technologies Proprietary and Confidential How To Integrate the API in Denodo 20200810 2 of 10

Goal

This document explains how to access Google Drive from Virtual DataPort by taking advantage of the Google Drive API. We will create a JSON data source specifying the resource we want to access and authenticate ourselves using OAuth 2.0.

Content

Google Drive offers a REST API with full capabilities to perform CRUD operations from our applications. Before creating a data source in Virtual DataPort, it is necessary to configure the Google Developer account to be able to authenticate an application using OAuth 2.0:

1. Access Console at https://console.developers.google.com. 2. Click on the Library tab, and search for the Google Drive API to enable it:

3. Go back to the Dashboard tab, and click on the Google Drive API. 4. In the Google Drive API overview page, click Create Credentials:

5. Give the following answers: How To Integrate the Google Drive API in Denodo 20200810 3 of 10

6. Give a name for the credentials, such as: How To Integrate the Google Drive API in Denodo 20200810 4 of 10

7. Click Done:

8. Once the OAuth 2.0 client ID is configured, its details can be found in the Credentials tab. Two values will be used for the OAuth 2.0 authentication, and they are known to Google and the application as: a. Client ID b. Client secret

Now that the API is enabled and the authentication is set, a JSON data source can be created in Virtual DataPort to access Google Drive’s REST API.

As an example, we will create a data source that searches for a filename via a parameterized query using the following request URL: https://www.googleapis.com/drive/v3/files?q=name+contains+'@name'

This request will return all the folders and with names containing the string passed as the name parameter.

1. Create a new JSON data source: How To Integrate the Google Drive API in Denodo 20200810 5 of 10

a. File > New > Data source > JSON b. In Design Studio, you can hover over the connected virtual database, and click on the three dots to go to New > Data source > JSON. 2. For the Data route, select HTTP Client. 3. In the “Configuration” section: a. For the HTTP method, select GET. b. For the URL, GET requests of this API follow this format: https://www.googleapis.com/drive/v3/files?q=name+contains+'@name'

4. In the “Authentication” section: a. Authentication: OAuth 2.0 b. Authorization Grant: Authorization code grant c. Client identifier: Give the one obtained from Google Developers Console. d. Client secret: Give the one obtained from Google Developers Console. e. Click Launch the OAuth 2.0 credentials wizard to help you obtain these credentials. i. Token endpoint URL: https://accounts.google.com/o/oauth2/token ii. Authorization server URL: https://accounts.google.com/o/oauth2/auth iii. Redirect URI: If your web container port is 9090, then use the default redirect URI. Otherwise, select Other, and replace the port in the default redirect URI with your web container port. iv. Scopes: https://www.googleapis.com/auth/drive Note: To see a list of the other scopes that can be used, check https://developers.google.com/drive/web/scopes. v. Check Set the “state” request parameter. vi. In Generate the authentication URL, click Generate and then Open URL. vii. In Paste authorization response URL, give the URL retrieved in the previous step. viii. Click OAuth 2.0 credentials. ix. Click Ok to fill the remaining fields in the “Authentication” section. 5. Click Save to save the data source. How To Integrate the Google Drive API in Denodo 20200810 6 of 10

When we create the data source and base view, a dialogue will ask for a value for the name parameter:

This is needed to send a sample request to the data source to test the connectivity and, when creating the base view, to introspect the schema.

The base view’s schema is created over the data source using the response obtained with the sample value. From the created base view, it is possible to search for files containing any specific string in their names: How To Integrate the Google Drive API in Denodo 20200810 7 of 10

This first example shows all the files containing “pdf” in their names. If we query the base view, we will see one row with an array field called “files”:

This array contains references to each of the files returned by the search, and we can access them by clicking on the “files” field: How To Integrate the Google Drive API in Denodo 20200810 8 of 10

If we want to access a single file’s complete information, it can be done by searching the exact filename or unique ID of the object. In this example, we will create a parameterized data source to get a file object by its ID. The Google Drive API URL for this is: https://www.googleapis.com/drive/v3/files/@{fileId}?fields=appProperties %2Ccapabilities%2CcontentHints%2CcreatedTime%2Cdescription%2CexplicitlyTrashed %2CfileExtension%2CfolderColorRgb%2CfullFileExtension%2CheadRevisionId %2CiconLink%2Cid%2CimageMediaMetadata%2CisAppAuthorized%2Ckind %2ClastModifyingUser%2Cmd5Checksum%2CmimeType%2CmodifiedByMeTime %2CmodifiedTime%2Cname%2CoriginalFilename%2CownedByMe%2Cowners %2Cparents%2Cpermissions%2Cproperties%2CquotaBytesUsed%2Cshared %2CsharedWithMeTime%2CsharingUser%2Csize%2Cspaces%2Cstarred %2CthumbnailLink%2Ctrashed%2Cversion%2CvideoMediaMetadata%2CviewedByMe %2CviewedByMeTime%2CviewersCanCopyContent%2CwebContentLink %2CwebViewLink%2CwritersCanShare

This URL includes an optional parameter called “fields.” This parameter allows us to select which fields containing information about the file are returned. If the “fields” How To Integrate the Google Drive API in Denodo 20200810 9 of 10 parameter is excluded, only a small subset of the fields will be part of this method’s response. We have chosen to include all possible fields for this example. We created a JSON data source following the same steps as before but giving the above method as the GET request URL:

Creating a base view on top of this data source returns detailed file information:

We can query this view with any file ID returned by the “bv_gdrive_search_by_name” view: How To Integrate the Google Drive API in Denodo 20200810 10 of 10

Multiple views can be created on top of the Google Drive API in this manner. Once the base views containing the necessary information are created, they can then be combined like any other views in Virtual DataPort. Using the two base views created in this document as an example, we could create a join view that uses a file ID to obtain complete information of the files returned by a keyword search.

References

Using OAuth 2.0 to Access Google APIs Using OAuth 2.0 for Installed Applications Retrieve and Use OAuth 2.0 Credentials Choose Auth Scopes Google Developers Console