drone29a / clj-oauth

OAuth Consumer support for Clojure
BSD 2-Clause "Simplified" License
273 stars 52 forks source link

How to get twitter verify_credentials ? #37

Open manish-2014 opened 10 years ago

manish-2014 commented 10 years ago

I used clj-oauth to successfully login to twitter and fetch access-token. However when I try to invoke twitter api for "https://api.twitter.com/1/account/verify_credentials.json", I am getting a 401.

I suspect the (http/get ... ) is not setting the credentials correctly.

  (defn handle-twitter-token-credentials  [oauth_token oauth_verifier]
     {:status 200
    :headers {"Content-Type" "text/html"}
    :body  (let [
             access-token-response (oauth/access-token consumer request-token oauth_verifier)
             _ (println " access-token-response: " access-token-response)

              req-credentials     (oauth/credentials consumer
                                (:oauth_token access-token-response)
                                (:oauth_token_secret access-token-response)
                                :GET
                                "https://api.twitter.com/1/account/verify_credentials.json"
                                )

              ; this is ok so far
             _ (println "credentials: " req-credentials) 
              ; this breaks at http/get with 401 . The req-credentials looks ok
              ; I think   http/get  is not setting the authorization headers correctly
             ;
             info (http/get "https://api.twitter.com/1/account/verify_credentials.json"
                            {:query-params req-credentials})

             _ (println "got info ")
             _ (println "class " (class info))
             _ (println (str into))

             ]
          (with-out-str "Ok")

        )} )
drone29a commented 10 years ago

Hello, thanks for the report. First, you should be using version 1.1 of the Twitter REST API. Please check if that works for you.

Are other authenticated Twitter REST API calls failing with a 401 as well?

drone29a commented 10 years ago

I should've tested a little more before commenting. The URL https://api.twitter.com/1/account/verify_credentials.json is for major version 1 and using 1.0 explicitly results in a different error.

Will take a closer look.