title: fetching tweets with Ruby returns `open_http': 400 Bad Request (OpenURI::HTTPError)
body: <p>I am new to Ruby. I have starting reading first chapter in <strong>Bastards Book Ruby</strong> i.e. <a href="http://ruby.bastardsbook.com/chapters/intro_tweet_fetch/#h-2-8" rel="nofollow">Tweet fetching</a> but the tutorial uses Twitter API v1. The response I got told me to use v1.1. So, I followed tutorials and wrote a program:</p>
  
  <pre><code>require 'oauth'
  
  def prepare_access_token(oauth_token, oauth_token_secret)
      consumer = OAuth::Consumer.new("apiKey", "APISecret", { :site =&gt; "https://api.twitter.com", :scheme =&gt; :header })
  
      token_hash = { :oauth_token =&gt; oauth_token, :oauth_token_secret =&gt; oauth_token_secret }
      access_token = OAuth::AccessToken.from_hash(consumer, token_hash )
  
      return access_token
  end
  
  access_token = prepare_access_token("AccessToken", "AccessTokenSecret")
  
  response = access_token.request(:get, "https://api.twitter.com/1.1/statuses/home_timeline.json")
  puts response 
  </code></pre>
  
  <p>Output: <code>#&lt;Net::HTTPOK:0x007fb7eb0885b8&gt;</code></p>
  
  <p>If I run program until here. It runs just fine. But, then if I add below content to fetch tweets and write to file. I get errors</p>
  
  <pre><code>twitter_user = "iAbhimanyuAryan"
  remote_base_url = "https://api.twitter.com/1.1/statuses/user_timeline.json?count=100&amp;screen_name="
  
  remote_full_url = remote_base_url + twitter_user
  
  tweets = open(remote_full_url).read
  
  my_local_filename = twitter_user + "-tweets.json"
  
  my_local_file = open(my_local_filename, "w")
        my_local_file.write(tweets)
  
  my_local_file.close    
  </code></pre>
  
  <p>Errors: </p>
  
  <pre><code>❯ ruby twitter.rb
  #&lt;Net::HTTPOK:0x007fbbfc9d75c8&gt;
  /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/open-uri.rb:358:in `open_http': 400 Bad Request (OpenURI::HTTPError)
      from /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/open-uri.rb:736:in `buffer_open'
      from /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/open-uri.rb:211:in `block in open_loop'
      from /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/open-uri.rb:209:in `catch'
      from /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/open-uri.rb:209:in `open_loop'
      from /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/open-uri.rb:150:in `open_uri'
      from /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/open-uri.rb:716:in `open'
      from /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/open-uri.rb:34:in `open'
      from twitter.rb:27:in `&lt;main&gt;'
  </code></pre>