问题描述:

i have a users which post adds on facebook. I want to validate their links that images is post on these links. i used curl but it cannot validate facebook urls, Can this is possible through facebook developer API or any other method. thanks

$url = 'https://www.facebook.com/photo.php?fbid=620056421410941&set=a.405109092905676.94648.100002197659601&type=1&theater';

$handle = curl_init($url);

curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);

$response = curl_exec($handle);

$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);

if($httpCode == 404) {

echo 'Not Available';

}

else

{

echo 'Available';

}

curl_close($handle);

网友答案:

Yeah you can do this using a slighter hacky way..

<?php

$url = 'https://www.facebook.com/photo.php?fbid=620056421410941&set=a.405109092905676.94648.100002197659601&type=1&theater';
$handle = curl_init($url);
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
curl_setopt($handle, CURLOPT_USERAGENT, $agent);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);  
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER , false);  //<-- Add this 
curl_setopt($handle, CURLOPT_FOLLOWLOCATION , true);  //<--- Add this too
$response = curl_exec($handle);

if(stripos($response,'This content is currently unavailable')!==false) { //<-- Inspect the source for this text
    echo 'Not Available';
}
else
{
    echo 'Available';
}
curl_close($handle);

Explanation :

  • Set the user agent to spoof facebook that you are using a valid web-browser.
  • You need to add the two more cURL parameters as shown.
  • Inspect the source , instead of HTTP code.
相关阅读:
Top