9

Background

I have an web app that enables its users to share individual items (posts) on Facebook. I set up a Facebook App to have a API key to do that with the Javascript SDK. It works well and I see the sharing stats in the Facebook App Insights.

The items people share on Facebook are photos and videos, and I'd like to track the total view count, including Facebok shares. Is it possible ?

What I tried

  • The graph API endpoint /{post_url}
    • Only gives the shares, comments and likes count
  • The graph API endpoint /{object_id}/insights/post_impressions
    • No good, it says the object does not exists *

(*) The docs specify "Only page posts" for that metric, so I guess this is not possible after all, as those posts are not on my App Page feed.

Workarounds

  • For videos, I guess I can watch the access logs?
  • About the the images, it seem they are cached in Facebook servers, right? Or does the image file gets hit on my server whenever there is a post view? Any possible way to get a cache invalider for the image so they get hit at each view?
  • Inferring the average number of view based on the other metrics. For example average_views = shares x A + comments x B + likes x C but that seem very approximate, and I don't know the most adequate values for A, B and C.

Thanks for your help

Pandaiolo
  • 11,165
  • 5
  • 38
  • 70

1 Answers1

-1

For a Keyword

Use the open graph API. Here is a live example querying how many likes "Coca Cola" has.

https://developers.facebook.com/tools/explorer/?method=GET&path=cocacola%3Ffields%3Dlikes

Which boils down to:

https://graph.facebook.com/cocacola?fields=likes

Which you could do in an AJAX GET Because of CORS Policy of browser.

The result is:

{
  "likes": 71717854, 
  "id": "40796308305"
}

For a Url

https://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22http://www.code.shouttoday.com%22

Also http://api.facebook.com/restserver.php?method=links.getStats&urls=http://code.shouttoday.com will show you all the data like 'Share Count', 'Like Count' and 'Comment Count' and total of all these.

Change the URL (i.e. http://code.shouttoday.com) as per your need.

This is the correct URL, I'm getting right results.

PHP Ajax Request

You Can Show Facebook Share/Like Count Like This: ( Tested and Verified)

$url = http://code.shouttoday.com // You can use inner pages

$rest_url = "http://api.facebook.com/restserver.php?format=json&method=links.getStats&urls=".urlencode($url);

$json = json_decode(file_get_contents($rest_url),true);


echo Facebook Shares = '.$json[0][share_count];

echo Facebook Likes = '.$json[0][like_count];

echo Facebook Comments = '.$json[0][comment_count];
Zigri2612
  • 2,279
  • 21
  • 33
  • You kind of repeat what I state in my question (first bullet point): only shares, likes and comments are available. Question is: how to measure the **views** – Pandaiolo Aug 17 '16 at 14:44