【问题标题】:clojure oauth and credentialsclojure oauth 和凭据
【发布时间】:2013-02-13 22:08:51
【问题描述】:

我需要一些关于clojure and 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 感到困惑,但是当我删除它时,我得到一个错误...

【问题讨论】:

  • 那个 api_key 应该是秘密的吗? 82d4...?
  • 它只是一个测试密钥,将在几个小时后过期......但我现在改变了数字......也许更安全;)
  • 如果您提供真实代码(无密钥)而不是 twitter 示例,将会很有帮助。
  • FWIW,这是一个也使用这个库的存储库(虽然也是 twitter):github.com/borkdude/whosnotfollowingme
  • 嘿,我知道你说你想使用使用 clj-oauth 的解决方案,而 Flickr 使用 OAuth 1,但我刚刚写了一篇关于使用 LinkedIn API (OAuth 2) 的条目,没有任何 oauth框架,我相信它可能有用(以防万一,整个 OAuth 和 104 行 Clojure 中的查询)。链接:malagastockholm.wordpress.com/2013/05/19/… 和回购:github.com/kikofernandez/clojure-linkedin

标签: oauth clojure flickr


【解决方案1】:

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 查询参数的映射:

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

现在我们要做的就是

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

【讨论】:

    猜你喜欢
    • 2011-05-09
    • 2018-11-22
    • 2021-01-09
    • 2015-03-06
    • 2014-05-04
    • 1970-01-01
    • 2014-04-17
    • 2015-12-06
    • 1970-01-01
    相关资源
    最近更新 更多