title: Can't get Twitter trends using PHP
body: <p>So I'm trying to make a fairly simple php script that fetches the latest worldwide trends from Twitter. Most of the code comes from another StackOverflow post, with some minor modifications. Unfortunately, regardless what I try, all I get is:</p>
  
  <pre><code>{"errors":[{"message":"Could not authenticate you","code":32}]}
  </code></pre>
  
  <p>Yet this same code works just fine to get timelines, get tweets, post tweets, etc... But when I try trends, for some reason it fails.</p>
  
  <pre><code>$twitterurl = "https://api.twitter.com/1.1/trends/place.json?id=1";
  
  $oauth_access_token = "XXXXXXXXXXXXXXXXXXX";
  $oauth_access_token_secret = "XXXXXXXXXXXXXXXXXX";
  $consumer_key = "XXXXXXXXXXXX";
  $consumer_secret = "XXXXXXXXXXXX";
  
  $oauth = array( 'oauth_consumer_key' =&gt; $consumer_key, 'oauth_nonce' =&gt; time(), 'oauth_signature_method' =&gt; 'HMAC-SHA1', 'oauth_token' =&gt; $oauth_access_token, 'oauth_timestamp' =&gt; time(), 'oauth_version' =&gt; '1.0');
  
  function buildBaseString($baseURI, $method, $params)
  {
      $r = array();
      ksort($params);
      foreach($params as $key=&gt;$value)
      {
          $r[] = "$key=" . rawurlencode($value);
      }
      return $method . "&amp;" . rawurlencode($baseURI) . '&amp;' . rawurlencode(implode('&amp;', $r));
  }
  
  function buildAuthorizationHeader($oauth)
  {
      $r = 'Authorization: OAuth ';
      $values = array();
      foreach($oauth as $key=&gt;$value)
      {
          $values[] = "$key=\"" . rawurlencode($value) . "\"";
      }
      $r .= implode(', ', $values);
      return $r;
  }
  
  $base_info = buildBaseString($twitterurl, 'GET', $oauth);
  $composite_key = rawurlencode($consumer_secret) . '&amp;' . rawurlencode($oauth_access_token_secret);
  $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
  $oauth['oauth_signature'] = $oauth_signature;
  
  $header = array(buildAuthorizationHeader($oauth), 'Expect:');
  $options = array( CURLOPT_HTTPHEADER =&gt; $header,
                CURLOPT_HEADER =&gt; false,
                CURLOPT_URL =&gt; $twitterurl,
                CURLOPT_RETURNTRANSFER =&gt; true,
                CURLOPT_SSL_VERIFYPEER =&gt; false);
  
  $feed = curl_init();
  curl_setopt_array($feed, $options);
  $json = curl_exec($feed);
  curl_close($feed);
  $trends = json_decode($json);
  
  print_r($json); 
  </code></pre>