Keep getting OAuth::Unauthorized error when using oauth and twitter ruby gems

前端 未结 8 1199
抹茶落季
抹茶落季 2020-12-12 16:47

I am using the ruby twitter gem and oauth to gain access to users twitter accounts. In my code, I have:

unless @user.twitter_authd?
      oauth = Twitter::O         


        
相关标签:
8条回答
  • 2020-12-12 17:27

    This was one of the most annoying things to debug that I have come across. I was outputting in a couple places by accident because the URL's are dynamic and they happened to not be defined in my test case (i use this to display chart data and there is not enough right now so the google chart api URL's are blank). This caused my browser to make multiple requests to my localhost when some pages were loaded. Somehow that made the oauth process crap out. Obviously there is no way for people on S.O. to know about my application specific issue so I had to answer my own question.

    0 讨论(0)
  • 2020-12-12 17:27

    I had this same problem and none of the suggestions in this thread worked for me.

    I found the problem for me was the TIMESTAMP on my request. The mobile device I was running my scripts on had a jacked up clock. When I updated the system time on my device to the correct time (i.e. now), all of my requests came back "200 OK" instead of "401 Unauthorized".

    0 讨论(0)
  • 2020-12-12 17:32

    A bit late to the party but just ran into the same issue myself. I tracked the issue down to the setup of my OAuth app in Twitter. I had initially not specified a callback URL as I was unsure of it.

    Once I had setup my rails app I went back to find Twitter had assumed I was a desktop application as I hadn't specified a callback URL. Once I changed this to website and entered a callback URL I stopped getting 400s.

    0 讨论(0)
  • 2020-12-12 17:32

    If you're getting error 401 - OAuth::Unauthorized, make sure you edit the settings of your Twitter application as follows:

    • Application Type: Browser
    • Callback URL: http://127.0.0.1:3000/auth/twitter/callback
    0 讨论(0)
  • 2020-12-12 17:36

    Twitter doesn't allow localhost as part of a valid callback URL.

    Instead use http://127.0.0.1:3000/auth/twitter/callback

    Hope this helps

    0 讨论(0)
  • 2020-12-12 17:39

    this is an issue about time synchronization of your system with twitter server.

    0 讨论(0)
提交回复
热议问题