The connector provides the capability to programmatically manage files and folders in the Google Drive.

This module supports Google Drive API v3.


Before using this connector in your Ballerina application, complete the following:


To use the Google Drive connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the connector

Import the ballerinax/ module into the Ballerina projects shown below.

import ballerinax/;

All the actions return a valid response or error. If the action is a success, then the requested resource is returned. If not, an error is returned.

Step 2: Create a new connector instance

Create a drive:ConnectionConfig with the OAuth2 tokens obtained, and initialize the connector with it.

onfigurable string refreshToken = ?;
onfigurable string clientId = ?;
onfigurable string clientSecret = ?;
onfigurable string refreshUrl = drive:REFRESH_URL;

rive:ConnectionConfig config = {
   auth: {
       clientId: clientId,
       clientSecret: clientSecret,
       refreshUrl: refreshUrl,
       refreshToken: refreshToken

rive:Client driveClient = new (config);

Step 3: Invoke the connector operation

  1. Now you can use the operations available within the connector. Note that they are in the form of remote operations.

    Following is an example on how to retrieve a file using the connector.

    Get file with given file ID

    public function main() returns error? {
        drive:File response = check driveClient->getFile(fileId);
        log:printInfo("Successfully retreived the file.");
  2. Use bal run command to compile and run the Ballerina program.

You can find a list of samples here

Other versions

See more...