Facebook /me/home FQL equivalent - facebook

to get the functionality of I want for my app I need to start using FQL.
For the main stream I was using:-
$fb_news_feed = $facebook->api('/me/home');
what would be the equivelent in FQL that returns the same JSON. My current FQL is below
$fb_feed_params = array(
'method' => 'fql.query',
'query' => "SELECT post_id, actor_id, target_id, message, likes, created_time, type FROM stream WHERE filter_key = 'nf' AND is_hidden = 0 LIMIT 100",
);
$fb_news_feed = $facebook->api($fb_feed_params);
how do I get the users name etc? I'm guessing I would have to do some kind of join like you would in mysql??

This query should do it -
SELECT name, username, pic from user WHERE uid IN (SELECT actor_id FROM stream WHERE filter_key = 'nf' AND is_hidden = 0 LIMIT 100)
Alternatively you could look at doing a multiquery. More information on multiqueries can be found on the facebook developers site:
https://developers.facebook.com/docs/reference/rest/fql.multiquery/

Related

Facebook page_fan returning NULL, can't check if user likes page

I'm working on a Facebook app and I need to know if the user likes a specific page or not.
I tried using:
$isFan = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT uid FROM page_fan WHERE page_id = 'SOMEPAGEID'
AND uid = me()"
));
It returns NULL.
I even tried the javascript SDK:
FB.api('/me/likes/SOMEPAGEID', function(response) {
console.log(response.data);
});
It returns nothing.
I'm asking for the following permissions:
$scope = "email,user_likes";
Am I missing something?
Edit: SELECT * was bad copy-paste... it's SELECT uid
Your permissions look correct but I don't think that FQL queries actually support SELECT *, you have to manually list the fields
So try changing your FQL query to
select page_id from page_fan WHERE uid = me() AND page_id = PAGE_ID
Or it might be you haven't encoded your query properly. This runs for me in the graph explorer https://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3Dselect%2Bpage_id%2Bfrom%2Bpage_fan%2BWHERE%2Buid%2B%253D%2Bme%2528%2529
fql?q=select+page_id+from+page_fan+WHERE+uid+%3D+me%28%29
so try using
$isFan = $facebook->api('/fql?q='.urlencode('select page_id from page_fan WHERE uid = me() AND page_id = PAGE_ID'));

facebook fql query album table not working with graph api php

$fql = 'SELECT name,aid,photo_count,owner FROM album WHERE owner='.$userId;
$fql = 'SELECT aid,owner,name FROM album WHERE owner IN
(SELECT uid1 FROM friend WHERE uid1 = 100002278102636 LIMIT 1 )';
I am using my codeigniter application to upload photo to an album which will be named current date.Creating album and all other uploads are working fine,but when i tried to select album name from album table using owner field its returning an empty array.But above query works fine with facebook test query widget
https://developers.facebook.com/tools/explorer?fql=SELECT%20aid%2Cowner%2Cname%20FROM%20album%20WHERE%20owner%3D100002278102636
i used API like this
$ret_obj1 = $this->facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
what am i doing wrong...Thanks in advance
My guess is that this is a permission issue. To get these results, you need to be authenticated as a user and have the user_photos and friends_photos permission in your access token. If you don't, the FQL query will return a result and Facebook will filter that result out before it is given to your app, giving an empty data set.
The other possibility is your access token does not belong to user 100002278102636. If that is the case, then the friend subquery will fail.
Also, you should be using album_object_id now instead of aid. It appears that the aid field (and pid) will be removed in November.
Have you tried running your $fql query through urlencode? You'll notice that the one on facebooks graph explorer is encoded but yours is not
$ret_obj1 = $this->facebook->api(array(
'method' => 'fql.query',
'query' => urlencode($fql),
));
As an aside - this query:
$fql = 'SELECT aid,owner,name FROM album WHERE owner IN
(SELECT uid1 FROM friend WHERE uid1 = 100002278102636 LIMIT 1 )';
You are selecting uid1 WHERE uid1 = a known value? Why not just do
$fql = 'SELECT aid,owner,name FROM album WHERE owner = 100002278102636 )';

Is there a way to get messages from specific user

Is it possible to get messages from specific user?
If I would like to get all messages where recipients are myself and x
I didn't find a way to create that kind of query, so is it possible?
var fbid = your_fbuid_here;
FB.api({
method: 'fql.query',
query: 'SELECT thread_id, author_id, created_time FROM message WHERE thread_id IN (SELECT thread_id FROM thread WHERE folder_id = 0) AND author_id = ' + fbid + ' ORDER BY created_time ASC LIMIT 1'
}, function ( threadresponse ) {
FB.api({
method: 'fql.query',
query: 'SELECT thread_id, body, author_id, created_time FROM message WHERE thread_id = ' + threadresponse[0].thread_id + ' ORDER BY created_time ASC'
}, function ( inboxresponse ) {
//do stuff here with results
});
});
or you can do this
var fbid =the _freind_fb_uid_here;
FB.api({
method: 'fql.query',
query: 'SELECT thread_id, body, author_id, created_time FROM message WHERE thread_id IN (SELECT thread_id FROM thread WHERE folder_id = 0) AND author_id = ' + fbid + ' ORDER BY created_time DESC'
}, function ( threadresponse ) {
//do stuff here with results
});
facebookfacebook-fqlfacebook-apifacebook-graph-apifacebook-fql-query
Now FQL don't have field author_id, only originator and snippet_author. But this fields contain wrong data. For example, userA send me (userB) message: userA create thread. Anyway I see, that originator have me (userB).
Best way use recipients:
SELECT recipients,snippet,object_id,updated_time,unread,unseen,thread_id FROM thread WHERE folder_id=0 AND recipients IN (userA_fid, userB_fid)
But it's also don't work and return empty data...

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.