Take the 2-minute tour ×

I've registered my mobile app (Sencha Touch) with Twitter and I have the appropriate keys to access version 1.1 of the API. Now I'm writing a web service to provide the JSON back to my mobile app. Here is what I have so far based on the ruby example provided by Twitter on this page.

require 'oauth'

class Twitter
  def initialize
    @consumer_key = "omitted"
    @consumer_secret = "omitted"
    @access_token = "omitted"
    @access_token_secret = "omitted"

  def pull_tweets(query)
    authorized_token = prepare_access_token(@access_token, @access_token_secret)
    response = authorized_token.request(:get, query)


  def prepare_access_token(oauth_token, oauth_token_secret)
    consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, { site: "https://api.twitter.com/", scheme: :header })
    token_hash = { oauth_token: oauth_token, oauth_token_secret: oauth_token_secret }
    access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
    return access_token

query = "https://api.twitter.com/1.1/statuses/home_timeline.json"
response = Twitter.new.pull_tweets(query)
p response

When I run this code I get #<Net::HTTPBadRequest 400 Bad Request readbody=true> as a response. After doing some research I found that this could be one of four things.

  • My authentication details are wrong
  • I'm being rate limited
  • Ruby is not formatting the query string properly (more details)
  • The query I'm using is wrong

I don't think I'm being rate limited because I've never managed to get a response, and I don't know how to check if I'm authenticating properly. Any help is much appreciated.

share|improve this question

Your Answer



Browse other questions tagged or ask your own question.