Julienh / Sharrre

Make your sharing widget! Sharrre is a jQuery plugin that allows you to create nice widgets sharing for Facebook, Twitter, Google Plus (with PHP script) and more.
sharrre.com
MIT License
1.04k stars 413 forks source link

Facebook graph changed! Share count no longer works. #112

Open jakewhiteley opened 11 years ago

jakewhiteley commented 11 years ago

It appears using https://graph.facebook.com/?ids=http://your-url-here.com, now only returns a share count HALF of the time.

The other half it returns a JSON object containing the OG data for that URL but no share count, like count or comment count.

This means half of my website has 0 shares on it, and half half have shares.

I've filed a long complaint at facebook as if they are removing support from Graph of a particular function, they should roll it out all at once or not at all.

Choosing to remove share counts from some URL's only = irritating.

The alternative is using Facebooks FQL method which does still return counts everytime.

EXAMPLE: here is the JSON object returned from https://graph.facebook.com/?ids=http://gkbcinc.com/aaron-swartz-and-the-ongoing-battle-for-the-internets-soul/

{
   "http://gkbcinc.com/aaron-swartz-and-the-ongoing-battle-for-the-internets-soul/": {
      "url": "http://gkbcinc.com/aaron-swartz-and-the-ongoing-battle-for-the-internets-soul/",
      "type": "article",
      "title": "Aaron Swartz and the Ongoing Battle for the Internet's Soul - GKBC",
      "locale": {
         "locale": "en_us"
      },
      "image": [
         {
            "url": "http://gkbcinc.com/wp-content/uploads/Aaron-Schwartz-300x200.jpg"
         },
         {
            "url": "http://gkbcinc.com/wp-content/uploads/ITU-conference.jpg"
         },
         {
            "url": "http://gkbcinc.com/wp-content/uploads/Anonymous.jpg"
         }
      ],
      "description": "Aaron Swartz's untimely death brings the debate about control of the internet into stark relief",
      "site_name": "GKBC",
      "updated_time": "2013-01-25T11:53:13+0000",
      "id": "190893914385022"
   }
}

No counts to be found anywhere.

jakewhiteley commented 11 years ago

And just so you know - Easily the best share count plugin out there. I have hacked my version of sharrre.js to always get the counts, but I don't want this issue getting picked up by others and ruining the reputation of your awesome project because Facebook can't make their mind up.

Julienh commented 11 years ago

Thanks jakewhiteley, I think Facebook remove counter when sharing = 0, see : https://graph.facebook.com/?ids=http://sharrre.com and https://graph.facebook.com/?ids=http://sharrreeeee.com

jakewhiteley commented 11 years ago

Thank you for the quick reply!

That may be true, but I was getting this on pages that 100% did have shares.

http://gkbcinc.com/the-gkbcinc-short-story-competition/ has 98 as a share total which using the Facebook developer sandbox highlighted when using FQL.

So a little more digging indicated that Facebook have stopped giving out Share counts via graph method for certain undisclosed pages as people are finding this all over the web.

Solution: Line 106:

facebook: "http://graph.facebook.com/?id={url}&callback=?",

To

facebook: "https://api.facebook.com/method/fql.query?format=json&query=SELECT+total_count+FROM+link_stat+WHERE+url+%3D+'{url}'",

then

Line 463:

else if(typeof json.shares !== "undefined"){  //Facebook
count += parseInt(json.shares, 10);
}

To

else if(typeof json[0].total_count !== "undefined"){  //Facebook
count += parseInt(json[0].total_count, 10);
}

And voila! 100% of the time share count bypassing Facebooks new 'change the way the API works but don't update the documentation' idea.

Try : https://api.facebook.com/method/fql.query?format=json&query=SELECT+total_count+FROM+link_stat+WHERE+url+%3D+'facebook.com'

To get a result

jakewhiteley commented 11 years ago

I should also say - I was sharing a page via the sharrre plugin and the number would update.

On refresh it would be back to 0 - so this proves that it is not just for pages with 0 shares.