list users who like page or url - facebook

I need to list users who like specific url or at least facebook page
I tried using both PHP and https://api.facebook.com/method/fql.query
I can see the number of likers for the URL
$arr[1]['url'] = 'http://example.com/test/test3.php?ref=gametest&fb_ref=gametest&fb_source=gametest';
$arr[1]['object_id'] = '10150930574980642';
require_once("facebook.php");
$facebook = new Facebook(array(
'appId' => '325617367526193',
'secret' => '6c40e01dd717431c9b7ec6ce68bf0c94',
));
I used http://developers.facebook.com/docs/reference/fql/like/ example to form similar query
$query = <<<FQL
SELECT user_id FROM like WHERE object_id="10150930574980642"
FQL;
$fql_query_url = 'https://graph.facebook.com/fql?q=' . rawurlencode ( $query );
$fql_query_url .= '&access_token=' . rawurlencode ( $facebook->getAccessToken() );
but the resulting link gives no data at all
{
"data": [
]
}
The same result via link with or without access_token
api.facebook.com/method/fql.query?query=SELECT%20user_id%20FROM%20like%20WHERE%20object_id%3D%2210150930574980642%22

The "like" table will only return the IDs of users who like the following objects (video, note, link, photo, or album).
You cannot find out the user Ids of people who like a particular page, only objects within that page.
e.g. The likes for an album on the Facebook Page (SELECT user_id FROM like WHERE object_id="10150146071791729"&access_token=[access_token])
If you want to get the users that have liked a particular link, you will need to get the object_id of this link first:
https://api.facebook.com/method/fql.query?query=SELECT url,site,id FROM object_url WHERE url IN ('http://developers.facebook.com')
This will return the object_id of the link http://developers.facebook.com.

Related

Working with facebook Like button and FSQL

I have develop Facebook application and added page tab on my page.
I have read Facebook documentation for canvas application development and adding application on page tab.
I want to show different page for people who click on Like button on my page and different page to people who not click on like button.
After reading documentation I found that it is possible using FSQL but I am not getting any result from my sql queries
https://developers.facebook.com/docs/reference/fql/url_like/
https://developers.facebook.com/docs/reference/fql/
require_once 'facebook.php';
// *** Add your Facebook API Key, Secret Key here ***
$appapikey = '*********';
$appsecret = '**********';
$facebook = new Facebook($appapikey, $appsecret);
// $user_id = $facebook->require_login();
//$fql = "select name from user where uid=me()";
//$fql = "SELECT user_id FROM like WHERE object_id='122706168308'";
$fql = "SELECT user_id, object_id, post_id FROM like WHERE user_id=me()";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
echo"hi";
echo"<pre>";
print_r($fqlResult);
echo"</pre>";
Any idea how to make it working?
Thanks.
did you authorized app at first ?
PS: its not FSQL its fql i mean you are not able to use all sql commands in fql

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?
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
First one is something that tells you how many likes selected url have.
Using second one you will get information about Page Object through page identifier

Get Facebook video thumbnail image URLs?

We can get the video thumb of YouTube videos by using the video ID in an URL the way defined below
$src = "http://img.youtube.com/vi/".$video_id."/default.jpg";
Similarly, how can I get the video thumb of Facebook videos? Is there any predefined URL in which we put the Facebook video ID and get the as like youtube defined in the way above?
Trying to do this as well but it does not appear so.
Example:
a video I have on a Page with
ID "1015030122022040"
has a thumbnail url of:
http://vthumb.ak.fbcdn.net/hvthumb-ak-ash2/51388_10150301225830401_10150301220220401_62962_1470_t.jpg
While another video with ID: 10150361184550401
has a thumbnail url of:
http://vthumb.ak.fbcdn.net/hvthumb-ak-snc4/162098_10150361242815401_10150361184550401_35242_2053_t.jpg
I looked through others and found no obvious pattern. You can however do an FQL to return the array of videos by uid.
Using some code from a tutorial, I edited the "sql query example" in Step Three to this:
try {
//get user id
$uid = $facebook->getUser();
//or you can use $uid = $fbme['id'];
$fql = "SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE owner=" . $uid;
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
}
catch(Exception $o){
d($o);
}
Then from his example was able to the view the arrays <?php d($fqlResult); ?>
And grabbed my most recent video thumbnail thusly:
<img src="<?php echo $fqlResult[0][thumbnail_link]; ?>" />
check this :http://www.cutevideoclub.com/php/facebook-video-thumbnail-with-video-id-php/
$fbvideoid="158952527492492";
$fql2 = "SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE vid=" . $fbvideoid;
use above query for detail see ref site:http://www.cutevideoclub.com/php/facebook-video-thumbnail-with-video-id-php/
or click here facebook video thumbnail with video id php

Retrieving posts and comments from a Facebook page

I want to retrieve all of the posts from a given facebook page along with the associated comments.
I wrote this code (app details obfuscated, replace with your own in order to run it).
<?php
require_once('facebook.php');
$facebook = new Facebook(array(
'appId' => 'MY_APP_ID',
'secret' => 'MY_APP_SECRET',
'cookie' => true,
));
$pages = array(
"stackoverflow" => 11239244970
);
$result = $facebook->api(array(
'method' => 'fql.multiquery',
'queries' => '{
"posts": "select post_id, source_id, actor_id, target_id, likes, message from stream where source_id = '.$pages["stackoverflow"].'",
"comments": "select post_id, text, username, fromid from comment where post_id in (select post_id from #posts)"
}'
));
echo json_encode($result);
?>
posts returns the expected results, but comments returns just one comment.
This example queries the stackoverflow facebook page
The comment returned from the comments query is "Joined!" (from this post). I can't figure out what's special about this comment.
Any thoughs?
I tried to find a solution playing with Graph Api
https://graph.facebook.com/me/fql?q=select message, comments from stream where source_id = 11239244970
is working but when returning comments it returns only the last 2. It's exaclty how Facebook itself shows the stream and comments with "View all XX comments" link.
To query the posts and comments together can be used:
https://graph.facebook.com/fql?q={"posts":"select post_id,message, comments from stream where source_id = 11239244970","comments": "select post_id, text, username from comment where post_id in (select post_id from #posts)"}&access_token=...
According to Facebook:
Each query of the stream table is limited to the previous 30 days or
50 posts, whichever is greater, however you can use time-specific
fields such as created_time along with FQL operators (such as < or >)
to retrieve a much greater range of posts.

Check if user is a fan of my Facebook app

How can I check thought the FB Javascript API if the current user is a fan of my app? I need to check this from within the page inserted into the FB's canvas IFRAME, throught the JS SDK...so that I can call a method of a local Flash, and do "something special" for that user.
In PHP, you can achieve this by using their PHP-SDK.
First you're gonna have to query their FQL database. Use the ff query (replace UID with the user's Id and PAGE_ID with your application's Id).
'SELECT uid, page_id FROM page_fan WHERE uid=UID AND page_id=PAGE_ID'
So your code might look like this:
$client = new Facebook(YOUR_PARAMS_HERE);
$result = $client->api(array(
'method' => 'fql.query',
'query' => 'SELECT uid, page_id, type FROM page_fan WHERE uid=1234 AND page_id=4321',
));
This returns an array similar to the ff:
array(
[0] = array(
[uid] = 1234
[page_id] = 4321
[type] = APPLICATION
)
)
FQL page_fan details here.