fql.get method return empty Array in Facebook Application with facebook-php-sdk-v2.1.2-4 - facebook

Recently I am trying to develop a facebook application that shows the STATUSES of loged in facebook user.
I am succeeded to retrieve information from user table using FQL. But right now I am using this following code to get data from status table.
****BEGIN :: CODE SECTION***********
$sql = "SELECT message,time FROM status WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = ".$myLoginId.")";
$param = array(
// 'method' => 'fql.query',
'method' => 'status.get',
'query' => $sql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
print_r($fqlResult);
***END:: CODE SECTION********
But everytimes it returns Empty Array.
Right Now I am using Library of facebook-php-sdk-v2.1.2-4-g2343fca.tar which I collect from github.com.
can anybody please give me a solution.
Thank in Advance.

You code is working just fine, just a small note, you can use me() to get the current user id:
$fql = "SELECT uid,message,time FROM status WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me())";
$fqlResult = $this->facebook->api(array(
'method' => 'fql.query',
'query' => $fql
));
AND once again, the most important part is acquiring the correct permissions, which are user_status (if you want to get your statuses) AND friends_status (to get your friends' statuses).

Related

facebook upcoming birthday fetching only this year

i want to fetch Facebook friend birthdays from current date to next year current day . todate is the date 364 days later to now in m/d. for this purpose first fql is to retrieve data from jan to current date and second one is for fetching data from current date to 31 dec. i want to apply pagination to upcoming birthdays for next 11 month and 29 days.the following queries are working and fetching the data.can anyone tell me the best way to do so. any suggestion will be highly appreciated.
$fromDate = date('m/d');
$past_birthdays = $facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT uid, name, birthday, birthday_date,substr(birthday_date,0,3) FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND birthday_date<'$toDate' AND birthday_date>='01/01' order by birthday_date",
'access_token' => $accessToken
));
if ($toDate > $fromDate) {
$condition = " AND birthday_date<'$toDate'";
} else {
$condition = "";
}
$upcoming_birthdays = $facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT uid, name, birthday, birthday_date,substr(birthday_date,0,3) FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND birthday_date>='$fromDate' $condition order by birthday_date",
'access_token' => $accessToken
));
as in your case i checked on facebook api explorer if you provide limit in your query, then its output in not consistent , the best way to solve your problem is load the whole birthday
list in array and show it in slots.
$fromDate = date('m/d');
$past_birthdays = "";
$upcoming_birthdays = $facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT uid, name, birthday, birthday_date, substr(birthday_date, 0,3) from user where uid in (select uid2 from friend where uid1=me()) and birthday_date >='$fromDate' order by birthday_date Limit 0,500",
'access_token' => $accessToken
));
$no = count($upcoming_birthdays); //exit;
if ($no < 500) {
$Limit2 = 500 - $no;
$past_birthdays = $facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT uid, name, birthday, birthday_date, substr(birthday_date, 0,3) from user where uid in (select uid2 from friend where uid1=me()) and birthday_date >='01/01' and birthday_date <= '$fromDate' order by birthday_date Limit 0,$Limit2",
'access_token' => $accessToken
));
//echo count($past_birthdays);exit;
$upcoming_birthdays = array_merge($upcoming_birthdays, $past_birthdays);
no need to take todate as you are fetching for whole year.this ccode is to fetch only 500 but run query for whole year.

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 )';

fql query fails - suspected auth issue

In a page, if I make a test fql query it works:
$fql = 'SELECT name from user where uid = ' . $user_id;
$ret_obj = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
echo '<pre>Name: ' . $ret_obj[0]['name'] . '</pre>';
However if I try to run this query, it fails:
$fql2 = 'SELECT uid, name, pic_square FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex =male';
$ret_obj2 = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql2,
));
echo '<pre>Name: ' . $ret_obj2[0]['name'] . '</pre>';
I suspect it is an auth problem, because the same fql query works in the graph api test tool!
If you want to checkout the full php code, it's the second example on this page:
https://developers.facebook.com/docs/reference/php/facebook-api/
You need just basic permissions for this query, so this is not the issue. Try adding double quotes around "male":
$fql2 = 'SELECT uid, name, pic_square FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex="male"';
Thanks for the support guys, the query wasn't working for 2 reasons:
1) I forgot the ; after the end of statement
2) In my code I used
`SELECT uid, name, pic_square, FROM`
instead of
`SELECT uid, name, pic_square FROM`

Error in FQL Query

This is My Code
$ids = join(", ",$man);
if ( !isset($_SESSION[$appID.'_FQLResult']) ) {
$FQLQuery = "SELECT uid, sex, pic_square FROM user WHERE uid in ($ids)";
$FQLResult = $facebook->api(array( 'method' => 'fql.query', 'query' => $FQLQuery, 'access_token'=>$fbme['access_token'] ));
$_SESSION[$appID.'_FQLResult'] = $FQLResult;
} else {
$FQLResult = $_SESSION[$appID.'_FQLResult'];
}
echo $ids;
echo $FQLResult;
There is an error
when i echo $ids it shows the value of $ids but when i echo $FQLResult is shows only "array" written whats wrong in this fql query?
how i can fix this?
I think there is something wrong in this query
$FQLQuery = "SELECT uid, sex, pic_square FROM user WHERE uid in ($ids)";
Use implode() directly instead of join()
After a successful API call, you should be expecting an array, so use print_r($FQLResult);
Always, if you are not sure of the type of the variable use var_dump()
You may want to use the new Graph API end-point (/fql?q=YOUR_QUERY), read here
Serialize your array before adding to sessions
Watch our of the session size limits!

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.