title: Using Bitly API to shorten URLs
body: <p>I found the Bitly API code below on <a href="http://ditio.net/2010/08/15/using-bit-ly-php-api/" rel="nofollow">this</a> site.  I'm having a hard time getting it to create and then echo a Bitly shortened URL for a variable called $fullurl.  How would I do that?  </p>
  
  <p><strong>EDIT:</strong> No error code appears, just no bitly shortened URL is shown.  </p>
  
  <p><strong>EDIT 2:</strong> <code>var_dump($response);</code> returns NULL</p>
  
  <p><strong>EDIT 3:</strong> I did replace the API login and key with my mine. </p>
  
  <p><strong>EDIT 4:</strong> I found the answer in one of the comments on the original tutorial.  My question was too basic for all you PHP pros: I simply needed to add <code>echo bitly_shorten($fullurl);</code> at the end.  </p>
  
  <p>Thanks in advance,</p>
  
  <p>John</p>
  
  <pre><code>function bitly_shorten($url)
  {
      $query = array(
          "version" =&gt; "2.0.1",
          "longUrl" =&gt; $url,
          "login" =&gt; API_LOGIN, // replace with your login
          "apiKey" =&gt; API_KEY // replace with your api key
      );
  
      $query = http_build_query($query);
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, "http://api.bit.ly/shorten?".$query);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
      $response = curl_exec($ch);
      curl_close($ch);
  
      $response = json_decode($response);
  
      if($response-&gt;errorCode == 0 &amp;&amp; $response-&gt;statusCode == "OK") {
          return $response-&gt;results-&gt;{$url}-&gt;shortUrl;
      } else {
          return null;
      }
  }
  </code></pre>