2013-02-13 116 views
8

我需要一些幫助clojure and oauthclojure oauth和憑證

我在最後一步被卡住了:用證書籤名請求。

(def credentials (oauth/credentials consumer 
            (:oauth_token access-token-response) 
            (:oauth_token_secret access-token-response) 
            :POST 
            "http://twitter.com/statuses/update.json" 
            {:status "posting from #clojure with #oauth"})) 

(http/put "http://twitter.com/statuses/update.json" 
      :query-params credentials) 

那就是github的例子。

現在,從Flickr的API,我有這樣的測試網址:

http://api.flickr.com/services/rest/?method=flickr.people.getPhotos 
&api_key=82d4d4ac421a5a22et4b49a04332c3ff 
&user_id=93029506%40N07&format=json&nojsoncallback=1 
&auth_token=72153452760816580-cd1e8e4ea15733c3 
&api_sig=b775474e44e403a79ec2a58d771e2022 

我不使用Twitter的...我使用Flickr的API,並希望得到用戶的圖片。

我現在的問題是:如何更改它適合flickr url的憑據? 我也對:status感到困惑,但是當我刪除它時,出現錯誤...

+0

是API_KEY應該是祕密嗎? 82d4 ...? – 2013-02-13 22:12:16

+0

它只是一個測試密鑰,將在幾個小時內過期......但我現在更改了數字......也許更安全;) – Nico 2013-02-13 22:15:25

+0

如果您給出真正的代碼(無鑰匙鍵)而不是Twitter示例,將會有所幫助。 – ivant 2013-02-21 10:38:17

回答

3

Twitter示例使用HTTP POST方法,但對於Flickr我們需要GET和flickr api。所以,我們做

(def credentials (oauth/credentials consumer 
           (:oauth_token access-token-response) 
           (:oauth_token_secret access-token-response) 
           :GET 
           "http://api.flickr.com/services/rest/" 
           query-params)) 

在Twitter的例子,我換成query-params規定了什麼才能發佈。它 是一個地圖,將被url編碼成類似status=posting%20from%20%23clojure%20with%20%23oauth的東西。相反,從API你提的要求對非OAuth的查詢PARAMS如下圖:

(def query-params {:method "flickr.people.getPhotos" :format "json" :user_id "[email protected]" :nojsoncallback 1}) 

現在我們所要做的就是

(http/get "http://api.flickr.com/services/rest/" {:query-params (merge credentials query-params)})