OAuth gives me error 401

I am trying to get a passkey, but I cannot get it to work. `` request_token.get_access_token is giving me 401 Unauthorized (OAuth :: Unauthorized) error. I copy the authorize_url into my browser, allow the application, I receive some kind of PIN from twitter but after hitting enter in my script I always get 401 error. I did some search and I found this helped error. I copy the authorize_url into my browser, allow the application, I receive some kind of PIN from twitter but after hitting enter in my script I always get 401 error. I did some search and I found this helped error. I copy the authorize_url into my browser, allow the application, I receive some kind of PIN from twitter but after hitting enter in my script I always get 401 error. I did some search and I found this helped access_token = request_token.get_access_token (: oauth_verifier => params [: oauth_verifier]) but it is giving me undefined local variable or params' for main:Object (NameError)

  • Twitter application type is client
  • ruby script is similar to (I followed this tutorial )
  • I would like to get out of this script access detail. Best without a PIN.

.

 gem 'oauth' require 'oauth/consumer' consumer_key = 'your key' consumer_secret ='your secret' consumer=OAuth::Consumer.new "consumer_key", "consumer_secret", {:site=>"http://twitter.com"} request_token = consumer.get_request_token puts request_token.token puts request_token.secret puts request_token.authorize_url puts "Hit enter when you have completed authorization." STDIN.gets access_token = request_token.get_access_token #access_token = request_token.get_access_token(:oauth_verifier => params[:oauth_verifier]) puts access_token.token puts access_token.secret puts puts access_token.inspect 
+4
source share
1 answer

I had the same problem. replace:

 STDIN.gets 

from:

 pin = (gets.chomp).to_i 

To_i is converted to an integer, which also performs space separation. Then you need to specify the contact when trying to get the acess token. If you do not, there is no evidence that the user has allowed your application.

 access_token = request_token.get_access_token(:oauth_verifier => pin) puts "Access Token : " + access_token.token puts "Access Secret : " + access_token.secret 
+5
source

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


All Articles