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.
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:
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:
This request will return all the folders and files with names containing the string passed as the name parameter.
Note: To see a list of the other scopes that can be used, check https://developers.google.com/drive/web/scopes.
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:
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:
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:
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” 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:
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.