Search code examples
facebookfacebook-graph-apifacebook-pagefacebook-opengraph

facebook fan pages and related open graph objects


If exist a facebook fan page like this:

https://www.facebook.com/HuffingtonPost 

I suppose to get likes count calling graph API:

https://graph.facebook.com/https://www.facebook.com/HuffingtonPost

Infact here I get:

{
    "id": "https://www.facebook.com/HuffingtonPost",
    "shares": 435839
}

On the other hand if I call

https://graph.facebook.com/HuffingtonPost

I get a more verbose output:

{
   "id": "18468761129",
   "name": "The Huffington Post",
   "picture": "http://profile.ak.fbcdn.net/hprofile-ak-ash2/188072_18468761129_6398033_s.jpg",
   "link": "http://www.facebook.com/HuffingtonPost",
   "likes": 435832,
   "category": "Website",
   "website": "http://www.facebook.com/HuffingtonPost",
   "username": "HuffingtonPost",
   "company_overview": "The Internet Newspaper\nNews | Blogs | Video | Community",
   "description": "The Huffington Post - The Internet Newspaper. - Company Overview: The Internet Newspaper News | Blogs | Video | Community | Facebook",

       [... omissis ...]

}

Can anybody tell me what's difference between these two opengraph objects?
There is also a slight difference between number of shares and likes. Why?

Update:

During last days graph api returned also object type, so I realized that:

  • First API call returns an link_stat type object.
  • Second API call returns a page type object.

In first case shares count should represent sum of:

  • number of likes of this URL
  • number of shares of this URL (this includes copy/pasting a link back to Facebook)
  • number of likes and comments on stories on Facebook about this URL
  • number of inbox messages containing this URL as an attachment.

In second case like count represents only itself

May somebody confirm me shares count correctness?


Solution

  • For the breakdown between likes, shares and comments (which are added up and used as the "likes" number on the likes button, you're better off using FQL.

    If you use OG, something like http://graph.facebook.com/http://example.com will show you:

    {
       "id": "http://example.com",
       "shares": 3
    }
    

    ... as you've noted above. If you use FQL, you can get the breakdown of each.

    <?php
    
    // require the php sdk
    require_once 'facebook-php-sdk/src/facebook.php';
    
    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId' => 'YOUR_APP_ID',
      'secret' => 'YOUR_APP_SECRET',
      'cookie' => true,
    ));
    
    $external_result = $facebook->api(array(
    'method' => 'fql.query',
    'query' => 'SELECT share_count, like_count, comment_count, total_count, click_count FROM link_stat WHERE url="http://example.com";'
    ));
    
    echo '<li>'.number_format($external_result[0]['like_count']).' likes, '.number_format($external_result[0]['share_count']).' shares';
    
    echo '<pre>';
    print_r($external_result);
    echo '</pre>';
    
    ?>
    

    This will display something on-screen like:

    * 1 likes, 2 shares
    Array
    (
        [0] => Array
            (
                [share_count] => 2
                [like_count] => 1
                [comment_count] => 0
                [total_count] => 3
                [click_count] => 0
            )
    
    )
    

    Also, SA now has a Facebook-specific site that may be helpful to you. :) facebook.stackoverflow.com