PHP cURL to Facebook insights report

     

I am using the Facebook Marketing API with php sdk to generate my insight report.


When my report is created successfully I can download it from browser in this URL:


  

www.facebook.com/ads/ads_insights/export_report?report_run_id=RUN_ID&format=csv&access_token=TOKEN

  

$fileName = "campaign_insights.csv";  $graph_url = 'https://www.facebook.com/ads/ads_insights/export_report?report_run_id='.$report_run.'&format=csv&access_token='.$access_token;
$path = "campaign_insights.csv";
set_time_limit(0);  $fp = fopen ($path 'w+');  $ch = curl_init();  curl_setopt($ch CURLOPT_TIMEOUT