Google Drive
Step 1: Create a connection
To create a Google Drive connection, go to the Cloud Console and, in the Connectors page accessed from the sidebar, select Google Drive. Follow the steps to authorize your Google account.
Step 2: Install the google-api-python-client
package
Once you have created the connection, you can use it in your code. We recommend using the google-api-python-client
library to interact with Google Sheets.
You can install it using the "Requirements" tab in the Editor or by running the following command in your terminal:
pip install google-api-python-client
Step 3: Using the connection
You can get your credentials by importing the get_gdrive_credentials
function from the abstra.connectors
module. This function will return the credentials you need to access your Google Drive.
Creating new files
from abstra.connectors import get_gdrive_credentials
from googleapiclient.discovery import build
credentials = get_gdrive_credentials()
service = build("drive", "v3", credentials=credentials)
files = service.files()
created_file = files.create(
body={
"name": "New File created from the Abstra integration",
},
).execute()
Listing files
Currently, you can only list files created by the Abstra integration. In the future, we’ll add support for selecting specific files from your Google Drive that the Abstra Connector can access and manage.
from abstra.connectors import get_gdrive_credentials
from googleapiclient.discovery import build
credentials = get_gdrive_credentials()
service = build("drive", "v3", credentials=credentials)
files = service.files()
results = files.list(pageSize=10, fields="nextPageToken, files(id, name)").execute()
items = results.get("files", [])
if not items:
print("No files found.")
else:
print("Files:")
for item in items:
print(f"{item['name']} ({item['id']})")
More Examples
To get started with the Google Drive API integration, check out the Quickstart guide. For more advanced use cases, refer to the Google Drive API reference