Facebook rest API现已弃用。Facebook *: https://api.facebook.com/method/links.getStats?urls=%%URL%%&格式= json
那么我怎样才能得到我的网站的Facebook分享数呢?
New Graph API v2.7
请使用以下代码。为您的网站创建应用程序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_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;
}