I’ve a facebook app which posts in the user wall. In the post there is a link (to my app) and in the liked page there is a like button.
Now I’m making a script that will run once per hour (set from the crontab). In that script I need to get two different likes count:
- Likes in the message posted in the wall.
- Likes done in my app (with the button).
For the first one I’ve made this code:
$result = $facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT user_id FROM like WHERE post_id="'.$idPost.'"'
));
$likesWall = count($result);
This code was working, but suddenly it is not. It throws this exception:
Fatal error: Uncaught Exception: 190:
Error validating access token: The
session is invalid because the user
logged out. thrown in C:\(…)\facebook\base_facebook.php
on line 656
For the second likes count
I really don’t know how I have to do it. I’ve tried:
$result = $facebook->api(array(
'method' => 'links.getStats',
'urls' => $canvasPage."somePage.php?id=".$id
));
But this throws:
Fatal error: Uncaught CurlException:
60: SSL certificate problem, verify
that the CA cert is OK. Details:
error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificate
verify failed thrown in
C:\(…)\facebook\base_facebook.php
on line 759
And then this was given to me: http://graph.facebook.com/?ids=http://apps.facebook.com/appName/somePage.php?id=68&metadata=1 where the bold part is the url in the like button I created. When I put it in the browser it returns me a JSON with some information (including the likes count) but I don’t know how to use it in my script.
More information:
Here is the code to define facebook object:
include_once 'facebook/facebook.php';
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $secret
));
I’m using the latest version the SDK (v3).
I found it!
I made it this way: