Facebook Analytics - 获取 Facebook post 的分享数?
Facebook Analytics - Get the share count for a Facebook post?
我正在使用 Facebook 分析(https://developers.facebook.com/) to get the share number of counts for a facebook post (on a wordpress website), and it was working well until someone made some requests to the post(when i access the post in my website, i make a request to facebook api to get number of shares per post). After i make some requests to the post, example: http://kosovotwopointzero.com/sistemi-i-shendetesise-nen-mikroskop/ 目前我禁用它来显示分享数量,因为它不起作用,Facebook api 被称为:
这是我使用的功能
function get_url_shares_count($url = '') {
$fbUrl = 'https://graph.facebook.com//v2.1/?id='.$url.'&access_token=??|??';
$request = wp_remote_get($fbUrl);
$data = json_decode($request['body']);
// return $data[0]->share_count;
return is_null($data->share) ? 0 : $data->share->share_count;
}
但几乎大多数时候 API 都会给我回复这个:
{
"error": {
"message": "(#4) Application request limit reached",
"type": "OAuthException",
"is_transient": true,
"code": 4,
"fbtrace_id": "GDs+M7u/zoO"
}
}
你能帮我找到一个解决方案吗?这个限制是 facebook 的政策还是我们正在使用的功能?
如果您通过任何可用的插件或联系 Facebook 的方式(如果有必要)帮助我们找到解决方案。
我的建议是获取数据;
- 每小时一次
- 每次用户再次登录
如何?
像这样的东西应该可以工作:
function YourFunctionName()
{
$HourAgo = date('m/d/Y h:i:s a', time() -(3600));
$newload = false;
if (isset($_SESSION['LastApiCall'])) {
if (strtotime($HourAgo) >= strtotime($_SESSION['LastApiCall'])) {
$newload = true;
}
}else{
$newload = true;
}
if ($newload) {
$content = 'your_url'
$_SESSION['apiData'] = json_decode($content);
// Handle api data
$_SESSION['LastApiCall'] = date('m/d/Y h:i:s a', time());
}
}
每次重新加载时检查 YourFunctionName(),如果用户注销则销毁每个会话
注意:没有测试这个
我正在使用 Facebook 分析(https://developers.facebook.com/) to get the share number of counts for a facebook post (on a wordpress website), and it was working well until someone made some requests to the post(when i access the post in my website, i make a request to facebook api to get number of shares per post). After i make some requests to the post, example: http://kosovotwopointzero.com/sistemi-i-shendetesise-nen-mikroskop/ 目前我禁用它来显示分享数量,因为它不起作用,Facebook api 被称为:
这是我使用的功能
function get_url_shares_count($url = '') {
$fbUrl = 'https://graph.facebook.com//v2.1/?id='.$url.'&access_token=??|??';
$request = wp_remote_get($fbUrl);
$data = json_decode($request['body']);
// return $data[0]->share_count;
return is_null($data->share) ? 0 : $data->share->share_count;
}
但几乎大多数时候 API 都会给我回复这个:
{
"error": {
"message": "(#4) Application request limit reached",
"type": "OAuthException",
"is_transient": true,
"code": 4,
"fbtrace_id": "GDs+M7u/zoO"
}
}
你能帮我找到一个解决方案吗?这个限制是 facebook 的政策还是我们正在使用的功能?
如果您通过任何可用的插件或联系 Facebook 的方式(如果有必要)帮助我们找到解决方案。
我的建议是获取数据;
- 每小时一次
- 每次用户再次登录
如何?
像这样的东西应该可以工作:
function YourFunctionName()
{
$HourAgo = date('m/d/Y h:i:s a', time() -(3600));
$newload = false;
if (isset($_SESSION['LastApiCall'])) {
if (strtotime($HourAgo) >= strtotime($_SESSION['LastApiCall'])) {
$newload = true;
}
}else{
$newload = true;
}
if ($newload) {
$content = 'your_url'
$_SESSION['apiData'] = json_decode($content);
// Handle api data
$_SESSION['LastApiCall'] = date('m/d/Y h:i:s a', time());
}
}
每次重新加载时检查 YourFunctionName(),如果用户注销则销毁每个会话
注意:没有测试这个