Keep getting Twitter :: Error :: Unauthorized, with only some users

I use the gem of Twitter (https://github.com/jnunemaker/twitter). Keep getting Twitter :: Error :: Unauthorized, with only a few users. For other users, the request is executed without any problems.

user = User.first client = Twitter::Client.new(:oauth_token => user.authentications.where(:provider => 'twitter').first.token, :oauth_token_secret => user.authentications.where(:provider => 'twitter').first.secret) client.follower_ids 

Exact error: Twitter::Error::Unauthorized: This method requires authentication.

This happens on a case by case basis. The problem affects a number of users in our system. The first thing you might think is that their oauth_token and oauth_token_secret may be invalid. I store these tokens in the same way that I store tokens for each user. Therefore, there is no reason to suspect that tokens may be invalid.

Does anyone know why?

+4
source share
2 answers

The error Could not authenticate with OAuth means that oauth_token and oauth_secret no longer valid.

Earlier today, we had similar reports that the values ​​copied directly from the access token section of this site did not work.

+1
source

I had the same problem and came up with a stupid solution. The twitter API has changed and you will need your oauth_token and your oauth_token_secret (even if you send your token to someone else). You must generate them on the Twitter developer page. Kind of double ... But it worked for me.

 Twitter.configure do |config| config.consumer_key = 'key' config.consumer_secret = 'secret' config.oauth_token = 'oauth_token' config.oauth_token_secret = 'oauth_token_secret' end 

Hope this helps!

0
source

Source: https://habr.com/ru/post/1389515/


All Articles