It usesGoogle Drive API with a Service Account. This method avoids interactive authentication and uses a service account key file for authentication, which is ideal for server environments.
-
Enable the Google Drive API for Your Project:
- Go to the Google Cloud Console.
- Enable the Google Drive API for your project.
-
Create a Service Account:
- Navigate to IAM & Admin > Service Accounts.
- Create a new service account and give it a descriptive name, e.g.,
Drive API Service Account. - Grant it the Editor role (or more restrictive roles depending on your needs).
-
Generate a Key File:
- Under the service account, go to the Keys section and click Add Key > Create New Key.
- Select JSON format.
- Download the JSON file and save it securely, e.g., as
service-account.json.
-
Share a Folder in Google Drive with the Service Account:
- The service account has its own email address (shown in the JSON file). Share a folder in your Google Drive with this email and give it appropriate permissions.
- Note the folder ID (found in the URL when you open the folder).
-
Update Your Code to Use the Service Account: Replace the current authentication logic with the following:
Here’s how you can update your Go program:
-
Replace
your-folder-id-here:- Use the ID of the folder you shared with the service account.
-
Place
service-account.json:- Save the service account JSON key file in the same directory as your program.
-
Install Google API Client Libraries: Run:
go get google.golang.org/api/drive/v3 google.golang.org/api/option
- No Interactive Authentication: Service accounts work without browser-based OAuth flows, ideal for servers.
- Persistent Access: Access is granted through shared folders, avoiding token expiration issues.
Let the monkeys team know if you face any issues!