Search code examples
ruby-on-railstwitterrest-client

Twitter REST API with Rails rest-client


I'm trying to connect to Twitter's REST API using application-only authentication. I get the bearer token, but the GET request doesn't work.

token = TOKEN
response = RestClient.get "https://api.twitter.com/1.1/followers/ids.json?screen_name=twitter", {headers: {'Authorization' => "Bearer #{token}"}}

Am I doing something incorrect with rest-client?


Solution

  • You don't need the "headers"-key. Since the hash after the URL is for headers your request will contain a header with the name "headers" rather than "Authoriziation".

    It should work by just removing "headers":

    RestClient.get "https://api.twitter.com/1.1/followers/ids.json?screen_name=twitter", {'Authorization' => "Bearer #{token}"}