我正在尝试在 php 中使用 curl 来抓取 facebook fanpage,但它只是给了我一个空白页面。这是我的代码。
function curlFunction($source_url){
$ch = curl_init();
$userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1';
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $source_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_ENCODING, "UTF-8" );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$html= curl_exec($ch);
curl_close($ch);
return $html;
}
$token = "CAACEdEose0cBADMEK5uLLfSTj1nZCG8eogAZBi6Dfkr4gJN9o6fFuyfEHkPtO94br9i9YP9gmiYPunHxRxr1PqU3YNy34PziACwEaMXl4NT9zZBMgdWD6WFh6mAL2dlqsjnYs9sKQ5sz7ZCVBn7ZA8lVrZCJRq8O0ZD";
$url = "https://graph.facebook.com/StarHub/feed?accesstoken=" . $token;
$html = curlFunction($url, $info);
echo $html;
我已经在其他网站上使用此功能来抓取页面,并且效果很好。然后我遇到了这个问题,当我使用 https 时它给了我空白页但是当我只使用 http 它工作正常,但是 facebook graph api 要求我使用 https 来获取内容。