title: How to CURL a Facebook ad report
body: <p>I want to download a Facebook ad report onto my server using CURL because sadly I dont have access to their Ad API and probably never will do.</p>
  
  <p>I successfully logged in to Facebook using CURL (I got an email from Facebook saying my account had been logged in from somewhere else so bingo)</p>
  
  <p>Code Im using for Facebook log in: <a href="http://www.daniweb.com/web-development/php/code/290893/facebook-login-with-curl">http://www.daniweb.com/web-development/php/code/290893/facebook-login-with-curl</a></p>
  
  <p>But the code that downloads the report isn't working. The CSV just shows blank (As it is default on the server)</p>
  
  <p>Any ideas? You can see the URL to the Facebook CSV file isn't direct so this may be part of the problem.... or maybe something with <code>$cookie</code> in the Facebook log in code?</p>
  
  <pre><code>$local_file = "letsbonus-ticket.csv";//This is the file where we save the information
  $remote_file = "http://www.facebook.com/ads/manage/download_report.php?act=44309118&amp;report_run_id=6016464099986&amp;format=csv&amp;source=email"; //Here is the file we are downloading
  
  
  $ch = curl_init();
  $fp = fopen ($local_file, 'w+');
  $ch = curl_init($remote_file);
  curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  curl_setopt($ch, CURLOPT_FILE, $fp);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_ENCODING, "");
  curl_exec($ch);
  curl_close($ch);
  fclose($fp);
  </code></pre>