A Clojure library that wraps the Google Java API for different Google Applications.
This library is partially typed using core.typed
. Run lein typed check
to type-check the library's code.
Latest test results (Thanks, CircleCI!):
If you're using Leiningen, just add this to your project.clj
:
[google-apps-clj "0.6.1"]
If you are using ClojureScript, there's a dependency conflict (see #22) between Google Closure Compiler and the Google Apps API library , so you'll have to add an exclusion, like so:
[google-apps-clj "0.6.1" :exclusions [com.google.guava/guava-jdk5]]
Check out CHANGELOG.md to see what's been updated lately.
The sheets v4 ns was substantially revised.
Major breaking changes were made to the Google Drive code in v0.5.0 which will require updating most of your code that interacts with Google Drive. Please see CHANGELOG.md for details.
In order to use any of these APIs, you must first use the Google OAuth 2.0 library to set up your credentials. All the APIs rely on the credentials received from setting up OAuth 2.0.
Log in to Google using the account you wish the credentials to be under
Navigate to the Developer's Console
Create a project and name it appropriately
On the project dashboard, find the "Use Google APIs" card and click the link to "Enable and manage APIs". On the left nav bar, select the credentials tab. You can also go directly to https://console.developers.google.com/apis/credentials?project=your-project-id (substituting in for your-project-id
, of course).
Navigate to Credentials and click Create new Client ID under OAuth. Choose "Installed application" and set up a consent screen if necessary.
Create a google-creds.edn file
Copy the Client ID, Client Secret, and Redirect URIs into your google-creds.edn. You will use the data in this file for getting the rest of your credententials and for the other APIs.
Read in your google-creds.edn file like so:
(edn/read-string (slurp "config/google-creds.edn"))
Call google-apps-clj.credentials/get-auth-map on this, along with the necessary OAuth scopes (eg ["https://www.googleapis.com/auth/drive" "https://docs.google.com/feeds/" "https://spreadsheets.google.com/feeds" "https://www.googleapis.com/auth/calendar"]
), and read in data and follow its instructions
Copy the returned data into your google-creds.edn file under the :auth-map
key. Reload it into your REPL.
You are now ready to use the other APIs with your credential file
Google also supports Service Account credentials for server-to-server API access. The credential is provided as a JSON file containing a private key and some other data.
To obtain a service credential:
GOOGLE_APPLICATION_CREDENTIALS
) to point to it~/.config/gcloud/application_default_credentials.json
(making directories as needed)%APPDATA%\gcloud\application_default_credentials.json
(making directories as needed)Now you can use google-apps-clj.credentials/default-credential
to load these credentials, and then
pass them into most places that might otherwise expect a google-ctx
. For example:
(let [scopes [com.google.api.services.drive.DriveScopes/DRIVE]
creds (google-apps-clj.credentials/default-credential scopes)]
(google-apps-clj.google-drive/list-files! creds "FOLDERIDFOLDERIDFOLDERIDFOLD"))
(note in this scenario that the service account user has to be given the appropriate permissions in Drive.
The service account user won't show up by name in searches, but it can be added as a viewer/editor using its
USERID@PROJECTID.iam.gserviceaccount.com
email address as found in the JSON credential file)
Copyright © SparkFund 2015-2017
Distributed under the Apache License, Version 2.0. See LICENSE.txt for details.
Can you improve this documentation? These fine people already did:
Matthew Dunn, Jeffrey Stanton, Donald Ball & Nathan SorensonEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close