clj-oauth icon indicating copy to clipboard operation
clj-oauth copied to clipboard

How to get twitter verify_credentials ?

Open manish-2014 opened this issue 10 years ago • 2 comments

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

        )} )

manish-2014 avatar Aug 14 '14 11:08 manish-2014

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 avatar Aug 14 '14 13:08 drone29a

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.

drone29a avatar Aug 14 '14 14:08 drone29a