I got an API to download Facebook leads in excel format shown like below,
https://www.facebook.com/ads/lead_gen/export_csv/?id=XXXXXXXXXX&type=form,
How can I download this excel sheet into my server by using PHP curl code ?
I tried:
$output_filename = "test.csv";
$host = "https://www.facebook.com/ads/lead_gen/export_csv/?id=XXXXXXXXXXX&type=form";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt($ch, CURLOPT_REFERER, "https://www.facebook.com");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
$fp = fopen($output_filename, 'w');
fwrite($fp, $result);
fclose($fp);
when I run this code like https://Ip/facebook/facebook.php,I am getting below response.
Can any one help on it please ?
Thanks Sandeep