title: How to base64 encode an image from the facebook api
body: <p>I am attempting to convert an image url provided by the facebook api into base64 format with cURL.</p>
  
  <p>the api provides a url as such:</p>
  
  <pre><code>https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/p180x540/72099_736078480783_68792122_n.jpg?oh=f3698c5eed12c1f2503b147d221f39d1&amp;oe=54C5BA4E&amp;__gda__=1418090980_c7af12de6b0dd8abe752f801c1d61e0d
  </code></pre>
  
  <p>The issue is that the url only works with the oh, oe and <strong>gda</strong> parameters included in the url string, there is no direct img url. Removing the params send you to a facebook error page.</p>
  
  <p>With the parameterized url my curl_exec is not getting correct image data. Is there a way to get the base64 data from facebook, or is there something I can do to get access the pure image url given the parameterized url?</p>
  
  <p>This is what my decode scrip looks like:</p>
  
  <pre><code>header('Access-Control-Allow-Origin: *');
  
    $url = $_GET['url'];
  
    try {
          $c = curl_init($url);
          curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
  
          $result = curl_exec($c);
          curl_close ($c);
  
          if(false===$result) {
             echo 'fail';
          } else {
             $base64 = "data:image/jpeg;charset=UTF-8;base64,".base64_encode($result);
             echo $base64;
  }
  } catch ( \ErrorException $e ) {
      echo 'fail';
  }
  </code></pre>