This file contains hidden or 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> (with-facebook-auth-by-name "Max Weber" (client/get [:me :friends])) |
This file contains hidden or 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
| (with-facebook-auth {:access-token "134211159981787|2._UqBc68omALVTLR_FM6DZg__.3600.129951..."} | |
| (client/get "https://graph.facebook.com/me/friends")) |
This file contains hidden or 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> (with-facebook-auth-by-name "Max Weber" (client/get "https://graph.facebook.com/me/friends")) | |
| {:status 200, :headers {"content-type" "text/javascript; charset=UTF-8", | |
| "date" "Mon, 07 Mar 2011 15:56:41 GMT", | |
| "cache-control" "private, no-cache, no-store, must-revalidate", | |
| "expires" "Sat, 01 Jan 2000 00:00:00 GMT", | |
| "etag" "\"bb3aff0d25be9397d666254583743b7a8bcfb60e\"", | |
| "x-powered-by" "HPHP", "content-length" "4462", | |
| "pragma" "no-cache", "connection" "close", "x-fb-server" "10.32.53.102"}, | |
| :body {:data [{:name "Friend 1", :id "id of friend one"} {:name "Friend 2", :id "id of friend two"} ... |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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", |