This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clj-facebook-graph.example> (facebook-auth-by-name) | |
{"Max Weber" {:access-token "134211159981787|2.NFMD8_yemOzJ6rIH3Ezukw__.3600.129951..."}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"error": { | |
"type": "OAuthException", | |
"message": "Error validating application." | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def server (start-server)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get | |
"Like #'request, but sets the :method and :url as appropriate." | |
[url & [req]] | |
(request (merge req {:method :get :url url}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user> (use 'clojure.pprint) | |
nil | |
user> (require '[clj-http.client :as client]) | |
nil | |
user> (def request (wrap-json-response-conversion (client/wrap-request #'clj-http.core/request))) | |
#'user/request | |
user> (pprint (:body (request {:method :get :url "https://graph.facebook.com/btaylor"}))) | |
{:id "220439", | |
:name "Bret Taylor", | |
:first_name "Bret", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.contrib.json) | |
(defn wrap-json-response-conversion [client] | |
"Automatically transforms the body of a response of a Facebook Graph API request from JSON to a Clojure | |
data structure through the use of clojure.contrib.json. It checks if the header Content-Type | |
is 'text/javascript' which the Facebook Graph API returns in the case of a JSON response." | |
(fn [req] | |
(let [{:keys [headers] :as resp} (client req) | |
content-type (headers "content-type")] | |
(if (and (not (nil? content-type)) | |
(.startsWith content-type "text/javascript")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user> (require '[clj-http.client :as client]) | |
nil | |
user> (use 'clojure.pprint) | |
nil | |
user> (pprint (client/get "https://graph.facebook.com/220439")) | |
{:status 200, | |
:headers | |
{"p3p" | |
"CP=\"Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p\"", | |
"content-type" "text/javascript; charset=UTF-8", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user> (use 'clojure.contrib.json) | |
nil | |
user> (read-json (slurp "https://graph.facebook.com/btaylor")) | |
{:id "220439", | |
:name "Bret Taylor", | |
:first_name "Bret", | |
:last_name "Taylor", | |
:link "http://www.facebook.com/btaylor", | |
:gender "male", | |
:locale "en_US"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user> (slurp "https://graph.facebook.com/btaylor") | |
"{\"id\":\"220439\", | |
\"name\":\"Bret Taylor\", | |
\"first_name\":\"Bret\", | |
\"last_name\":\"Taylor\", | |
\"link\":\"http:\\/\\/www.facebook.com\\/btaylor\", | |
\"gender\":\"male\", | |
\"locale\":\"en_US\"}" |
NewerOlder