Facebook rest API现已弃用。 Facebook *:https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
那么如何才能获得我网站的Facebook分享数。
New Graph API v2.7
答案 0 :(得分:0)
请使用此波士顿代码。 为您的网站创建应用程序ID并调用共享页面URL它将返回共享计数。 您可以使用curl库从Facebook检索数据
$ json_string = file_get_contents_curl(“https://graph.facebook.com/v2.7/?id=http://example.com/xyz/&access_token=123456789002599|abcdSXS_PJNQ5iEBH098_ABC”);
$ json = json_decode($ json_string,true);
echo $ json ['share'] ['share_count']
卷曲代码private function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
$cont = curl_exec($ch);
if (curl_error($ch)) {
return false;
}
return $cont;
}