Skip to content

Instantly share code, notes, and snippets.

@mikebroberts
Last active December 23, 2015 06:39
Show Gist options
  • Save mikebroberts/6595266 to your computer and use it in GitHub Desktop.
Save mikebroberts/6595266 to your computer and use it in GitHub Desktop.
Clojure code to authenticate against Instagram's API. Requires clj-http (tested against [clj-http "0.7.0"]).
(ns instagram
"Functions to authenticate against Instagram's API.
See http://instagram.com/developer/authentication/ for parameter details."
(:require [clj-http.client :as client]))
(defn create-auth-url [client-id redirect-uri]
(str "https://api.instagram.com/oauth/authorize/?client_id=" client-id
"&redirect_uri=" redirect-uri
"&response_type=code"))
; ToDo - error checking
(defn request-access-token
"Request access-token, given code supplied via redirect callback.
Returns {:access_token token :user user}, as specified in the API documentation"
[client-id client-secret redirect-uri code]
(-> (client/post "https://api.instagram.com/oauth/access_token" {
:as :json
:multipart [
{:name "client_id" :content client-id}
{:name "client_secret" :content client-secret}
{:name "grant_type" :content "authorization_code"}
{:name "redirect_uri" :content redirect-uri}
{:name "code" :content code}]})
(:body)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment