To use the Google Drive API in your Python script, you need to create a Google Cloud Project, enable the Drive API, and set up OAuth credentials. Here's a step-by-step guide:
✅ Step 1: Go to Google Cloud Console
- Open https://console.cloud.google.com/
- Sign in with your Google account.
✅ Step 2: Create a New Project
- At the top-left, click on the project dropdown (you might see "Select a project" or your current project).
- Click New Project.
- Enter a Project Name (e.g.,
Drive API Script).
- Optionally, choose an organization (if applicable).
- Click Create.
Wait a few seconds while the project is created.
✅ Step 3: Enable the Google Drive API
- Once the project is ready, go to the Navigation menu (☰) > APIs & Services > Dashboard.
- Click + ENABLE APIS AND SERVICES at the top.
- In the search bar, type Google Drive API.
- Click on Google Drive API from the results.
- Click Enable.
✅ Step 4: Set Up OAuth Consent Screen
This is required for scripts that access user data via OAuth.
- From the left sidebar, go to APIs & Services > OAuth consent screen.
- Choose User Type:
- If you're the only user, select External (recommended for personal apps).
- For internal use within your organization, choose Internal.
- Click Create.
Fill out the Consent Screen:
- App name: e.g.,
Drive File Reader
- User support email: your email
- Developer contact information: your email
- Click Save and Continue
- You can skip Scopes unless you're adding specific permissions beyond basic read access.
- Under Test users, add your own email so you can test the app without publishing.
- Click Save and Continue again.
✅ Step 5: Create OAuth 2.0 Client ID
Now you’ll generate credentials for your app:
- Go to APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Application type:
- Select Desktop app if running locally (most common for Python scripts)
- Name it something like
Drive Script
- Click Create
Download JSON:
- After creating, a dialog will show your Client ID and Client Secret
- Click Download JSON (this file is usually named
credentials.json)
- Save this file in the same directory as your Python script
✅ Step 6: Run Your Script
Once you have:
- The Drive API enabled
- The OAuth credentials (
credentials.json) downloaded
- The script code updated with your file ID and random.org API key
You can run your script:
python your_script.py
The first time you run it, it will open a browser window asking you to log in and grant access to Google Drive. After that, it will save the token in token.json for future use.
📌 Summary Checklist
| Task | Status |
|---|
| Create Google Cloud Project | ✅ |
| Enable Google Drive API | ✅ |
| Configure OAuth Consent Screen | ✅ |
| Create OAuth 2.0 Desktop Credentials | ✅ |
Download credentials.json | ✅ |
Use credentials.json in your script | ✅ |
If you want, I can help you write a minimal script just to test the authentication flow with Google Drive!