Support » Plugin: WordPress Social Sharing Plugin - Social Warfare » Facebook API Share Count Not Accurate

  • I was trying to figure out why my Share Count was so low on Facebook when being counted by Social Warfare. I assumed it was Social Warfare having issues with the cache, but not the case.

    I’ve tested the URL it uses to get the “share_count” variable, and that variable is wrong for some reason.

    On our facebook page it says a specific URL has been shared 108 times. But, the API returns the “share_count” as 16 times. Obviously this isn’t matching up.

    On that open call I tried adding engagement, which also reports:

    “engagement”: {
    “count”: 16,
    “social_sentence”: “16 people like this.”
    }

    Also not right. Over 400 likes, so not sure where it is getting that. Maybe facebook only wants us using the id?=URL query just to get the object id and use that with api key?

    Cheers
    Ryan

Viewing 6 replies - 1 through 6 (of 6 total)
  • Going through your code, I found the swp_fetch_facebook_shares function.

    $json_string = swp_file_get_contents_curl(‘https://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=’.$url);

    restserver no longer works, so not sure if you are still trying to call that function.

    Cheers
    Ryan

    Seeing that you guys used to use “total_count” and are instead favoring “share_count” after Facebook update, I modified the Social Warfare facebook.php file and share-count-class.php to do this instead:

    function swp_fetch_facebook_shares($url) { 
    		$url = rawurlencode($url);
    		$json_string = swp_file_get_contents_curl('https://graph.facebook.com/?id=' . $url .'&fields=og_object{likes.summary(true)}');
    		$json = json_decode($json_string, true);
    		return isset($json['og_object']['likes']['summary']['total_count'])?intval($json['og_object']['likes']['summary']['total_count']):0;
    	}

    That will report total_count, as it did before the latest Social Warfare update.

    Plugin Author WarfarePlugins

    (@warfareplugins)

    We no longer use ANY functions in the share-count-class.php, but instead replaced all of that functionality with share-count-function.php. I just haven’t gotten around to removing the class version of the file yet. So the reason it has the deprecated API in that file is because we haven’t used that file in about 6 – 8 months now, at least. We are now using the API found on line 45 of Facebook.php

    So any efforts to fix something in share-count-class.php will only result in wasted time.

    Does that help?

    Yeah, I thought that may be the case, so I updated the “facebook.php” file as well in the social-networks directory to call for “total_count”

    Working good now.

    Plugin Author WarfarePlugins

    (@warfareplugins)

    Can you show me the line you changed in Facebook.php?

    Yep! Sorry for delay, was out of town:

    /*****************************************************************
    *                                                                *
    *   #3: Generate the API Share Count Request URL	             *
    *                                                                *
    ******************************************************************/
    	function swp_facebook_request_link($url) {
    		$request_url = 'https://graph.facebook.com/?id=' . $url .'&fields=og_object{likes.summary(true)}';
    		return $request_url;
    	}
    /*****************************************************************
    *                                                                *
    *   #4: Parse the Response to get the share count	             *
    *                                                                *
    ******************************************************************/
    	function swp_format_facebook_response($response) {
    		$response = json_decode($response, true);
    		return isset($response['og_object']['likes']['summary']['total_count'])?intval($response['og_object']['likes']['summary']['total_count']):0;
    	}

    You can also do “Engagement” og_object, which gives a slightly different count.

    On the Facebook Developers Group, they did acknowledge that the definition of “share_count” had changed, hence why many saw their share_count average plummet.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Facebook API Share Count Not Accurate’ is closed to new replies.