Giter VIP home page Giter VIP logo

google's Introduction

Google API for Clojure

(Works nicely with Roll)


roll/google {:git/url "https://github.com/dimovich/google"
             :sha "7bd7facaea72ae39c61e3593a680fa7db84d4ce3"}

Usage

(ns my.app
  (:require [roll.google :as google]))


(google/init "credentials.edn")


(def sheet-id "< sheet id >")


(google/sheet-append sheet-id [["some" "data"]
                               ["more" "data"]])


(google/sheet-values sheet-id)


(google/send-message
 (->>
  ["To: [email protected]"
   "Subject: ..."
   "some message"]
     
  (interpose "\n")
  (apply str)))


;; You can easily add more api endpoints as needed.

Usage with Integrant

{:roll/google "credentials.edn"}

Optaining Google Credentials

Create a new project in Google API console, and create new OAuth client ID credentials. Run the following code at the REPL using your client-id and client-secret:

;; Google OAuth2 access token generation
;;


(require '[clj-oauth2.client :as oauth2])


(def credentials
  {:creds
   {:client-id ",,,,,",
    :client-secret ",,,,,",
    :scope ["https://www.googleapis.com/auth/gmail.send"
            "https://www.googleapis.com/auth/spreadsheets"],
    :redirect-uri "http://localhost",
    :grant-type "authorization_code",
    :authorization-uri "https://accounts.google.com/o/oauth2/auth",
    :access-query-param :access_token,
    :access-token-uri "https://accounts.google.com/o/oauth2/token",
    :access-type "online",
    :approval_prompt ""}})


;; get request link

(def auth-req
  (oauth2/make-auth-request (:creds credentials)))


;; navigate to the link inside auth-req and get code


(def code "<... insert code ...>")


;; get token
  
(def token (oauth2/get-access-token
            (:creds credentials)
            {:code code}
            auth-req))



;; save credentials

(->> (assoc credentials :token token)
     (spit "credentials.edn"))

google's People

Contributors

dimovich avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.