Google APIs with OAuth 2.0 in your API client
Google's APIs (Drive, Calendar, Sheets, Gmail and the rest) act on a user's data, so they need OAuth 2.0: the user signs in with Google and approves what your client may do. That's more setup than an API key, but your API client can run the whole flow for you, and then refresh the token when it expires.
Step 1: Google Cloud setup
In the Google Cloud console, in a project for testing:
- Enable the API you want, for example the Google Drive API (APIs & Services → Library).
- Configure the consent screen (OAuth consent screen). For testing, keep the app in testing mode and add your own Google account as a test user.
- Create credentials → OAuth client ID, with the application type Desktop app. Copy the client ID and client secret.
A Desktop app client allows the local callback that Requestarium listens on (http://127.0.0.1:8765/callback), so there's no redirect URI to register.
Step 2: OAuth settings on the collection
Create a collection called Google APIs, open its Authorization tab and choose OAuth 2.0:
| Field | Value |
|---|---|
| Grant type | Authorization code (PKCE) |
| Authorization URL | https://accounts.google.com/o/oauth2/v2/auth |
| Token URL | https://oauth2.googleapis.com/token |
| Client ID | {{googleClientId}} |
| Client secret | {{googleClientSecret}} |
| Scope | https://www.googleapis.com/auth/drive.readonly |
Keep the client ID and secret in an environment, with the secret marked as secret.
Step 3: Get a token
Click Get new access token. Your browser opens Google's sign-in page. Choose your test account and approve the scopes. Google redirects back to the local callback, and the token is stored with the collection, encrypted. Every request set to Inherit auth now sends Authorization: Bearer ….
Step 4: Call the API
List the files in Drive:
GET https://www.googleapis.com/drive/v3/files?pageSize=10&fields=files(id,name,mimeType,modifiedTime),nextPageTokenconst body = pm.response.json();
pm.test('lists files', () => {
pm.response.to.have.status(200);
pm.expect(body.files).to.be.an('array');
});
pm.environment.set('pageToken', body.nextPageToken || '');The fields parameter limits what comes back. Google APIs return a lot by default, and asking for less makes responses faster and tests clearer.
Some other useful first requests:
GET https://www.googleapis.com/calendar/v3/calendars/primary/events?maxResults=10&singleEvents=true&orderBy=startTime&timeMin={{$isoTimestamp}}
GET https://sheets.googleapis.com/v4/spreadsheets/{{spreadsheetId}}/values/Sheet1!A1:D10
GET https://www.googleapis.com/oauth2/v3/userinfoEach needs its own scope added to the collection (calendar.readonly, spreadsheets.readonly, openid email), and a new token after you change scopes.
Step 5: Errors you'll see
| Status | Usual cause |
|---|---|
401 with UNAUTHENTICATED | The access token expired: refresh it or get a new one |
403 with insufficientPermissions or ACCESS_TOKEN_SCOPE_INSUFFICIENT | The token lacks a scope this call needs |
403 with accessNotConfigured | The API isn't enabled in your Google Cloud project |
400 redirect_uri_mismatch during sign-in | The OAuth client isn't a Desktop app, or a web client lacks the callback URL |
429 or 403 rateLimitExceeded | Per-user or per-project quota |
What about CI?
Authorization code tokens belong to a person, so they're a poor fit for CI. For automated runs against Google APIs, use a service account where the API supports it (for example Drive files shared with the service account, or Workspace with domain-wide delegation), and fetch its token in a request at the start of the collection. The pattern is the same as in OAuth in CI.