(注意如果你不理解 clojure,我可以翻译 Java 中的代码,请询问)
我正在将 scribe 与 clojure 一起使用,我发现使用 twitter 登录有一些问题,我正在使用的代码:
(def twitter-service
(-> (doto
(ServiceBuilder.)
(.provider (TwitterApi$Authenticate.))
(.apiKey "apikey")
(.apiSecret "apisecret")
(.callback "https://morgan-siscia.rhcloud.com/tatata/"))
(.build)))
(def tokens (atom {}))
(defn get-token []
(.getRequestToken twitter-service))
(defn get-twitter-url [token]
(swap! tokens assoc (.getToken token) token)
(.getAuthorizationUrl twitter-service token))
(defn get-info-twitter [oauth-token oauth-veri]
(let [token (get @tokens oauth-token)
verifier (Verifier. oauth-veri)
access-token (.getAccessToken twitter-service token verifier)
request (doto (OAuthRequest. (Verb/POST)
"https://api.twitter.com/oauth/access_token")
(.addOAuthParameter "oauth_token" oauth-token)
(.addBodyParameter "oauth_verifier" oauth-veri))]
(do
(.signRequest twitter-service access-token request)
(swap! tokens dissoc oauth-token))
(.getBody (.send request))))
该代码是java代码的直接翻译,但是它不起作用。
当我调用 (get-info-twitter "the-oauth-code" "the verifier code") twitter 返回错误:
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<request>/oauth/access_token</request>
<error>The access_token method must be called with a request_token</error>
</hash>
老实说,我不知道我做错了什么,有人可以帮助我吗?