0

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.

enter image description here

Can any one help on it please ?

Thanks Sandeep

  • could any one help on it please ? – MURALA SANDEEP Jul 08 '22 at 06:56
  • To use the API, I bet you need to register and use credentials. – Markus Zeller Jul 08 '22 at 07:59
  • @MarkusZeller thanks for response, I created Facebook app in developer tool and based on it I have created access token and I have followed this code https://stackoverflow.com/questions/54877083/php-curl-to-verify-facebook-api-login-access-token-on-server I am getting ```login valid``` I have run that code in that condition but same error which I posted in question – MURALA SANDEEP Jul 08 '22 at 08:03
  • The error in the browser is irrelevant. Is there any curl error? – Markus Zeller Jul 08 '22 at 08:07
  • @MarkusZeller thank for your replay ,I can't see any error in my curl and i am using chrome updated browser – MURALA SANDEEP Jul 08 '22 at 08:18

0 Answers0