clojure oauth and credentials

泄露秘密 提交于 2020-02-29 17:50:09

问题


I need some help with clojure and oauth.

I got stuck at the last step: signing the request with the credentials.

(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)

Thats the example from github.

Now, from the flickr API I have this test-url:

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

I dont use twitter... I use the flickr api and want to GET the pictures of a user.

My question is now: How do I have to change the credentials that it fits the flickr url? I am also confused about the :status but when I delete it I get an error...


回答1:


The Twitter example uses the HTTP POST method, but for Flickr we want GET and the flickr api. So we do

(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))

In the twitter example, what I replaced with query-params specifies what get posted. It is a map that will be url-encoded into something like status=posting%20from%20%23clojure%20with%20%23oauth. Conversely, the request from the API you mention has the following map for the non-oauth query-params:

(def query-params {:method "flickr.people.getPhotos" :format "json" :user_id "93029506@N07" :nojsoncallback 1})

Now all we have to do is

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


来源:https://stackoverflow.com/questions/14864142/clojure-oauth-and-credentials

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!