title: php cURL and Instagram Photos
body: <p>So someone Tweets a link to a photo on Instagram : <a href="http://instagr.am/p/QSVkR8LS3H/" rel="nofollow">http://instagr.am/p/QSVkR8LS3H/</a></p>
  
  <p>This redirects from <a href="http://t.co/bOJ4EX2j">http://t.co/bOJ4EX2j</a> to <a href="http://instagr.am/p/QSVkR8LS3H/" rel="nofollow">http://instagr.am/p/QSVkR8LS3H/</a> to the actual Instagram page <a href="http://instagram.com/p/QSVkR8LS3H/" rel="nofollow">http://instagram.com/p/QSVkR8LS3H/</a> where the photo resides.</p>
  
  <p>Cool. All that is good and well. Now I want a cURL to follow the tweeted link and download that final page, that contains the &lt; img > of the photo. Script looks basically like this :</p>
  
  <pre><code> $target = 'http://t.co/bOJ4EX2j';
  
   $ch = curl_init();
  
   curl_setopt ($ch, CURLOPT_HTTPGET,        TRUE);
   curl_setopt ($ch, CURLOPT_POST,           FALSE);
   curl_setopt ($ch, CURLOPT_COOKIEJAR,      COOKIE_FILE);   // Defined Constant
   curl_setopt ($ch, CURLOPT_COOKIEFILE,     COOKIE_FILE);
   curl_setopt ($ch, CURLOPT_TIMEOUT,        CURL_TIMEOUT);  // Defined Constant
   curl_setopt ($ch, CURLOPT_USERAGENT,      WEBBOT_NAME);   // Defined Constant
   curl_setopt ($ch, CURLOPT_URL,            $target);       // Target site
   curl_setopt ($ch, CURLOPT_REFERER,        '');            // Referer value
   curl_setopt ($ch, CURLOPT_VERBOSE,        FALSE);         // Minimize logs
   curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);         // No certificate
   curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, TRUE);          // Follow redirects
   curl_setopt ($ch, CURLOPT_MAXREDIRS,      4);             // Limit redirections to four
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);          // Return in string
  
  # Create return array
  $return_array['FILE']   = curl_exec($ch); 
  $return_array['STATUS'] = curl_getinfo($ch);
  $return_array['ERROR']  = curl_error($ch);
  
  # Close PHP/CURL handle
  curl_close($ch);
  
  return $return_array;
  </code></pre>
  
  <p>Now this script has many more components but that's the just of the cURL part. Now, it does manage to spit back that it landed on the correct final page <a href="http://instagram.com/p/QSVkR8LS3H/" rel="nofollow">http://instagram.com/p/QSVkR8LS3H/</a>) where the image is - but this is what the $return_array['FILE'] spits out :</p>
  
  <pre><code> 500 Server Error
  
   An internal server error occurred.
  </code></pre>
  
  <p>Even when if you navigate to the page in your browser, with cookie's off, and not signed into Instagram (if you were) the page loads completely!</p>
  
  <p>What the hell am I missing that's not allowing this to cURL script to download the Instagram page?! It works on just about every other page I try it! Just not Instagram.com?!</p>
  
  <p>Please someone help me crack this nut of a issue - I'd greatly appreciate any help or insight anyone might have.</p>