A GitHub Action to download files from Google Drive using either OAuth2 or Service Account authentication.
[!IMPORTANT] OAuth2 Authentication Recommended: Google has deprecated certain uses of service accounts and is encouraging the use of OAuth2 for better security and user control. This action now supports both authentication methods for backward compatibility, but OAuth2 is recommended for new implementations.
- Download files from Google Drive by filename or file ID
- Support for wildcard patterns in filenames (learn more)
- Two authentication methods: OAuth2 (recommended) and Service Account (legacy)
- Secure handling of credentials and tokens
OAuth2 provides better security and user control over permissions. To set up OAuth2 authentication:
- Go to the Google Cloud Console
- Create or select a project
- Enable the Google Drive API
- Go to "Credentials" and create an OAuth 2.0 Client ID
- Configure the OAuth consent screen if not already done
- Use a tool like Google OAuth Playground or your own application to generate a refresh token
Service accounts are still supported for backward compatibility, but OAuth2 is preferred for new implementations.
- Go to the Google Cloud Console
- Create or select a project
- Enable the Google Drive API
- Go to "Credentials" and create a Service Account
- Download the JSON key file
- Share your Google Drive folder/files with the service account email
- name: Download from Google Drive
uses: your-username/google-drive-download@v1
with:
authType: 'oauth'
clientId: ${{ secrets.GOOGLE_CLIENT_ID }}
clientSecret: ${{ secrets.GOOGLE_CLIENT_SECRET }}
refreshToken: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
folderId: 'your-folder-id'
filename: 'file-to-download.pdf'
destination: './downloads/'- name: Download from Google Drive
uses: your-username/google-drive-download@v1
with:
authType: 'service' # Optional, defaults to 'service'
credentials: ${{ secrets.GOOGLE_CREDENTIALS }}
folderId: 'your-folder-id'
filename: 'file-to-download.pdf'
destination: './downloads/'- name: Download specific file
uses: your-username/google-drive-download@v1
with:
authType: 'oauth'
clientId: ${{ secrets.GOOGLE_CLIENT_ID }}
clientSecret: ${{ secrets.GOOGLE_CLIENT_SECRET }}
refreshToken: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
fileId: 'specific-file-id'
destination: './downloads/'| Name | Description | Required | Default |
|---|---|---|---|
authType |
Authentication type: oauth or service |
No | service |
credentials |
Service account credentials JSON (required for service auth) | No* | |
clientId |
OAuth2 client ID (required for oauth auth) | No* | |
clientSecret |
OAuth2 client secret (required for oauth auth) | No* | |
refreshToken |
OAuth2 refresh token (required for oauth auth) | No* | |
filename |
Name of the file to download. Supports wildcards | No** | |
fileId |
ID of the specific file to download | No** | |
folderId |
ID of the parent folder to search in | Yes | |
destination |
Path to save the downloaded file(s) | Yes |
* Required based on authentication type ** Either filename or fileId must
be provided
Add these secrets to your repository:
GOOGLE_CLIENT_ID: Your OAuth2 client IDGOOGLE_CLIENT_SECRET: Your OAuth2 client secretGOOGLE_REFRESH_TOKEN: Your OAuth2 refresh token
Add this secret to your repository:
GOOGLE_CREDENTIALS: The entire contents of your service account JSON key file
- name: Download all PDFs
uses: your-username/google-drive-download@v1
with:
authType: 'oauth'
clientId: ${{ secrets.GOOGLE_CLIENT_ID }}
clientSecret: ${{ secrets.GOOGLE_CLIENT_SECRET }}
refreshToken: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
folderId: 'your-folder-id'
filename: '*.pdf'
destination: './pdfs/'- name: Download from Google Drive
id: download
uses: your-username/google-drive-download@v1
continue-on-error: true
with:
authType: 'oauth'
clientId: ${{ secrets.GOOGLE_CLIENT_ID }}
clientSecret: ${{ secrets.GOOGLE_CLIENT_SECRET }}
refreshToken: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
folderId: 'your-folder-id'
filename: 'important-file.txt'
destination: './downloads/'
- name: Handle download failure
if: steps.download.outcome == 'failure'
run: echo "Download failed, using fallback method"If you're currently using service account authentication and want to migrate to OAuth2:
- Set up OAuth2 credentials in Google Cloud Console
- Generate a refresh token
- Update your workflow to use the new authentication parameters
- Update your repository secrets
The action maintains backward compatibility, so you can migrate at your own pace.
-
Permission Denied: Make sure the Google Drive files/folders are shared with your service account email or that your OAuth2 application has the necessary permissions.
-
File Not Found: Verify the
folderIdandfilenameare correct. The folder ID can be found in the Google Drive URL. -
Authentication Errors:
- For OAuth2: Check that your client ID, client secret, and refresh token are correct
- For Service Accounts: Ensure the JSON credentials are properly formatted and the service account has access
-
API Quota Exceeded: Google Drive API has usage limits. Consider implementing retry logic or reducing the frequency of requests.
This project is licensed under the MIT License - see the LICENSE file for details.