我试图通过这条PHP线获得Facebook帐户的喜欢数量:
$content = file_get_contents('http://graph.facebook.com/facebook?fields=likes');
这项工作在我的本地服务器上。问题是这似乎不适用于在线服务器(var_dump($ content)返回值" false")。
我真的不太明白为什么这只适用于我的本地服务器。有人已经遇到过这个问题吗?
由于
答案 0 :(得分:1)
考虑切换到curl,与API交互更好。
$postData = http_build_query(
[
'fields' => 'likes'
]
);
$ch = curl_init();
$endpoint = sprintf('%s?%s', 'http://graph.facebook.com/facebook', $postData);
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);