Last active
May 26, 2024 08:13
-
-
Save ihorvorotnov/9132596 to your computer and use it in GitHub Desktop.
Get number of shares from social platforms
Guys need some Advice. Please Check my code if correct... I cant make it work:
/* Get Facebook Data
-------------------------------------------------- */
public function getFacebookData($domain)
{
try
{
$callback_url = "https://graph.facebook.com/v2.1/?";
$data = array(
'id' => "SELECT share_count, like_count, comment_count FROM link_stat WHERE url='$domain'"
);
$curl_response = $this->curl->get($callback_url . http_build_query($data, '', '&'));
if ($curl_response->headers['Status-Code'] == "200") {
$parse_response = json_decode($curl_response, true);
$fb_share_count = $parse_response['data'][0]['share_count'];
$fb_like_count = $parse_response['data'][0]['like_count'];
$fb_comment_count = $parse_response['data'][0]['comment_count'];
} else {
$fb_share_count = 0;
$fb_like_count = 0;
$fb_comment_count = 0;
}
$response = array(
'status' => 'success',
'data' => array(
'fb_share_count' => filter_var($fb_share_count, FILTER_SANITIZE_NUMBER_INT),
'fb_like_count' => filter_var($fb_like_count, FILTER_SANITIZE_NUMBER_INT),
'fb_comment_count' => filter_var($fb_comment_count, FILTER_SANITIZE_NUMBER_INT)
)
);
}
catch (Exception $e)
{
$response = array(
'status' => 'error',
'msg' => $e->getMessage()
);
}
return $response;
}
@ElchinIsmayilov check please my code..still cant get a share from facebook
Hi, does anyone have a solution for the Twitter counter?
ok.ru:
https://connect.ok.ru/dk?st.cmd=extLike&tp=json&ref=https://ya.ru/
• For Twitter, use http://twitcount.com/ or https://jsoon.digitiminimi.com/service_usage.html.
• For Facebook, use https://www.sharedcount.com/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Facebook new share count api: http://graph.facebook.com/?id=your_url
Twitter share count is removed, so no way to get it, don't try it.