title: Using Twitter OAuth to authenticate API calls for trends
body: <p>I am working on a website that allows the user to search for the top ten twitter trends in a city or country.  At first I was only relying on Twitter's Rest API, but I was having a lot of rate limit issues (at school my rate limit disappears faster than I have a chance to use it).  I know that authenticating my API calls will help me to better deal with this issue (Authenticated API calls are charged to the authenticating user’s limit while unauthenticated API calls are deducted from the calling IP address’ allotment).</p>
  
  <p>I implemented @abraham's PHP library (<a href="https://github.com/abraham/twitteroauth" rel="nofollow noreferrer">https://github.com/abraham/twitteroauth</a>), unfortunately my API calls aren't being authenticated.  I know I have implemented @abraham's PHP library, because it prints out my user information at the end like it should.  I have my twitter trend search underneath it but the API call isn't being authenticated.  I am not sure how to fix this, and any help would really be appreciated!</p>
  
  <p>This is what I use to get the top ten trends by country:
      
  
  <pre><code>function showContent(){
  
  // we're going to point to Yahoo's APIs
  $BASE_URL = "https://query.yahooapis.com/v1/public/yql";
  
  // the following code should only run if we've submitted a form
  if(isset($_REQUEST['location']))
  {
      // set a variable named "location" to whatever we passed from the form
      $location = $_REQUEST['location'];
  
      // Form YQL query and build URI to YQL Web service in two steps:
  
      // first, we show the query
      $yql_query = "select woeid from geo.places where text='$location'";
      // then we combine the $BASE_URL and query (urlencoded) together
      $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&amp;format=json";
  
      //var_dump($location);
  
      // show what we're calling
      // echo $yql_query_url;
  
      // Make call with cURL (curl pulls webpages - it's very common)
      $session = curl_init($yql_query_url);
      curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
      $json = curl_exec($session);
  
      // Convert JSON to PHP object 
      $phpObj = json_decode($json);
  
      // Confirm that results were returned before parsing
      if(!is_null($phpObj-&gt;query-&gt;results)){
  
  
        // Parse results and extract data to display
        foreach($phpObj-&gt;query-&gt;results as $result){
      //var_dump($result);    
       $woeid = $result[0]-&gt;woeid;
  
  
       if (is_numeric ($location)) 
           {
      echo "&lt;span style='color:red; padding-left: 245px;'&gt;Please enter a city or a country&lt;/span&gt;";
      } 
      else if(empty($result)){
       echo "No results found";
      }
      else {
      /*  echo "The woeid of $location is $woeid &lt;br /&gt;"; */
       }  
      } 
      }
  
      $jsontrends=file_get_contents("http://api.twitter.com/1/trends/".$woeid.".json"); 
  
      $phpObj2 = json_decode($jsontrends, true);
  
      echo "&lt;h3 style='margin-top:20px'&gt;TRENDS: ".$phpObj2[0]['locations'][0]['name']."&lt;/h3&gt; \r\n";
  
      $data = $phpObj2[0]['trends']; 
  
      foreach ($data as $item) { 
  
      echo "&lt;br /&gt;&lt;a href=\"".$item['url']."\" target=\"_blank\"&gt;".$item['name']."&lt;/a&gt;\r\n";
  
      echo "&lt;br /&gt; \r\n"; 
  
      }
      if(empty($item)){
      echo "No results found";
      }
  
      }
      }
  </code></pre>
  
  <p>I then add it to @abraham's html.inc file (along with some php to see the rate limit status) and html.inc is included in the index.php:</p>
  
  <pre><code>&lt;h1&gt;Top Twitter Trends&lt;/h1&gt;                 
  &lt;form name='mainForm' method="get"&gt;
  &lt;input name='location' id='location' type='text'/&gt;&lt;br/&gt;
  &lt;button id='lookUpTrends'&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;?php showContent(); 
  
  $ratelimit = file_get_contents("http://api.twitter.com/1/account/rate_limit_status.json"); 
  
  echo $ratelimit; 
  ?&gt;  
  &lt;/div&gt;
  </code></pre>
  
  <p>@abraham's index.php file has some example calls, and since my call doesn't look like this I think that is probably why it isn't being authenticated.</p>
  
  <pre><code>    /* Some example calls */
  
      //$connection-&gt;post('statuses/update', array('status' =&gt; date(DATE_RFC822)));
      //$connection-&gt;post('statuses/destroy', array('id' =&gt; 5437877770));
      //$connection-&gt;post('friendships/create', array('id' =&gt; 9436992));
      //$connection-&gt;post('friendships/destroy', array('id' =&gt; 9436992));
  </code></pre>
  
  <p>Please help me find what I need to fix so that my API calls are authenticated.</p>
  
  <p><strong><em>update 10-21</em></strong></p>
  
  <p>I think in order to make an authenticated API call I need to include something like this is my code:</p>
  
  <pre><code>$connection-&gt;get('trends/place', array('id' =&gt; $woeid));
  </code></pre>
  
  <p>It didn't fix my problem, but maybe it is on the right track?</p>