我有一个用户在facebook上添加了帖子。我想验证他们在这些链接上发布图片的链接。我使用curl但它无法验证facebook网址,这可以通过facebook开发者API或任何其他方法实现。感谢
$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);
答案 0 :(得分:0)
是的,你可以使用更轻松的 hacky 方式做到这一点..
<?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);
cURL
参数,如图所示。