GGG
GGG

Reputation: 670

PHP - cURL request not working

I'm trying to use cURL in PHP to retrieve the HTML of https://www.facebook.com/video.php?v=720617444660843, but it's not printing nothing and curl_error is returning nothing.

This is the code I'm using:

$defaults = array(
    CURLOPT_URL => "https://www.facebook.com/video.php?v=720617444660843",
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_TIMEOUT => 4
);

$ch = curl_init();
curl_setopt_array($ch, $defaults);
if( ! ($result = curl_exec($ch)))
{
    trigger_error(curl_error($ch));
}
curl_close($ch);
echo $result;

Upvotes: 0

Views: 1540

Answers (1)

Bhumi Shah
Bhumi Shah

Reputation: 9466

You need to pass user agent

$defaults = array(
CURLOPT_URL => "https://www.facebook.com/video.php?v=720617444660843",
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4,
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.16 (KHTML, like Gecko) \ Chrome/24.0.1304.0 Safari/537.16'
);

Upvotes: 1

Related Questions