Role of the OAuth app and API key

googledrive helps you obtain a token to work with the Google Drive API from R primarily through the drive_auth() function. Under the hood, that process relies on an OAuth client and secret, a.k.a. an “OAuth app”.

googledrive can also make unauthorized calls to the Google Drive API, for example accessing a file available to “Anyone with a link”, by sending an API key, instead of a user token.

If there is a problem with googledrive’s internal OAuth app or API key or if you would prefer to use your own, you can configure this. Below we describe how.

There is a section for the OAuth app, then for the API key, both of which describe googledrive v1.0.0 and higher. There’s a section at the end with similar info for earlier versions of googledrive, but we strongly advise upgrading.

Get an OAuth app and tell googledrive about it

Follow the instructions in the gargle article How to get your own API credentials to get an OAuth client ID and secret. Now register it with googledrive.

Method 1: Create an OAuth app directly, providing the client ID as key and client secret as secret.

Method 2: Create an OAuth app by providing the path to the JSON file downloaded from the Google Cloud Platform Console.

Confirm success and carry on! You can see the currently configured OAuth app like so:

You should see your own app there now.

For the rest of this R session, when you get a new token with drive_auth(), your OAuth app is used.

Get an API key and tell googledrive about it

Follow the instructions in the gargle article How to get your own API credentials to get an API key. You probably want to use the same GCP project to create both your OAuth app (above) and your API key. Now register it with googledrive.

drive_auth_configure(api_key = "YOUR_API_KEY_GOES_HERE")

Confirm success and carry on! You can see the currently configured API key like so:

You should see your own API key now.

For the rest of this R session, if you go into a de-authorized state via drive_deauth(), your API key will be sent with the request.

Instructions for googledrive v0.1.3 and earlier

What’s changed? The old drive_auth_config() has been soft-deprecated, in favor of drive_auth_configure().

OAuth app, Method 1: Create an OAuth app directly, providing the client ID as key and client secret as secret.

OAuth app, Method 2: Create an OAuth app by providing the path to the JSON file downloaded from the Google Cloud Platform Console.

API key:

drive_auth_config(api_key = "YOUR_API_KEY_GOES_HERE")