I've followed Google's instructions for generating a local client_secret.json file for programmatic access to my Google Docs, but it's not clear to me how to use this in Mathematica.

There are many related answers here already, but most seem outdated and none mention how to use client_secret.json.

How do I use my Google API client_secret.json to access my Google Docs? For example, how would I import the contents of a Google Sheet?

  • $\begingroup$ client_secrets.json just stores all the info you’ll then pass to the OAuth connection schemes described elsewhere on the site. You can always import it and use the data in one of the other answers. $\endgroup$ – b3m2a1 Nov 14 '17 at 16:50
  • $\begingroup$ @b3m2a1: Well, yes. The question is how to do that (and how to do it in the current, updated, idiom). $\endgroup$ – orome Nov 14 '17 at 17:00

Here's how I decided to include this in my service connections.

First, I tweaked my template to search out one of these files in my paclet or the "ApplicationData" subdir of $UserBaseDirectory:


Then I download my client_secrets.json and save it to "$UserBaseDirectory/ApplicationData/ServiceConnections/GoogleDrive/client_secrets.json"

Finally I take my standard service connection template and pass this as the client config:

$clientInfo["OAuth"] =
   "Client" -> "OAuth",
   "ClientID" :> googledrivegetclientdata["ClientID"],
   "ClientSecret" :> googledrivegetclientdata["ClientSecret"],
   "AuthorizeEndpoint" :>
   "AccessEndpoint" :>
   "RedirectURI" :>
   "AuthorizationScope" :>
   "AuthorizationResponseType" -> "code",
   "Fetch" -> GDRawImport,
   "Information" -> $serviceDescription

The only interesting thing there is the googledrivegetclientdata calls. Basically at load time I import from "client_secrets.json" and then pass those to Mathematica's OAuth flow.

This then works fine. Obviously I can't provide my "client_secrets.json" in my paclet, but you can install the paclet like so:


And put your own "client_secrets.json" at ""$UserBaseDirectory/ApplicationData/ServiceConnections/GoogleDrive/client_secrets.json"

And assuming I didn't mess anything up it should work on your machine too.

That paclet itself is a little glitchy and I don't have time now to expand or patch it, but if you look at its innards it should be clear enough what's happening.

| improve this answer | |
  • $\begingroup$ How about without a paclet. I don't use packages or paclets. $\endgroup$ – orome Nov 15 '17 at 13:26
  • $\begingroup$ @orome time consuming and not worth it for me. In that case just do what was suggested earlier: take C.E.’s answer previously and just import the file into the request parameters. $\endgroup$ – b3m2a1 Nov 15 '17 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.