I cannot figure out what is wrong with this fql.multiquery and cannot seem to find any examples of the new sdk with fql.multiquery.
Ultimately I want to get the page name and page id(s) of the visiting user pages which they both administrator and are fans of.
$queries = '{
"page_admin_ids" :
"SELECT page_id FROM page_admin WHERE uid = ' . $afid . ' LIMIT 5",
"page_fan_ids" :
"SELECT page_id FROM page_fan WHERE page_id IN (SELECT page_id FROM #page_admin_ids)",
"page_name_and_id" :
"SELECT name, page_id FROM page WHERE page_id IN (SELECT page_id FROM #page_fan_ids)"
}';
$attachment = array("method"=>"fql.multiquery","query"=>$queries,'access_token'=>$access_token);
$ret_code = $facebook->api($attachment);
print_r($ret_code); die();
$multiQuery = array(
'likes' =>
' SELECT ... FROM like ...',
'users' =>
' SELECT uid, name ' .
' FROM user ' .
' WHERE uid IN (SELECT user_id FROM #likes) ',
);
$multiQueryResult = $facebook->api(array(
'method' => 'fql.multiquery',
'queries' => $multiQuery
));
I think you should replace "query" parameter in $attachment with "queries".
Related
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.
I am new to Facebook development and I am playing around with some proof of concepts. How would I write a query to get a list of all my friends that like the U2 page?
I am thinking something like this.
var result = fb.Get("fql", new { q = "SELECT name FROM user WHERE uid IN (SELECT uid1 FROM friend WHERE uid2=me()) AND 'U2' IN like" });
also checkins
var result = fb.Get("fql", new { q = "SELECT checkin_id, author_uid, page_id FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND page_id IN (SELECT page_id FROM page WHERE name = 'MyPlace')" });
Also is there a query builder tool?
This should do it (example is with the PHP SDK (v3.x) )
$page_id = ID OF PAGE
$result = $facebook->api(array(
'method' => 'fql.multiquery',
'queries' => array(
'friends_liking_page' => 'SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND page_id = ' . $page_id,
'result' => 'SELECT uid, name, pic FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() AND (uid2 IN (SELECT uid FROM #friends_liking_page)))'
)
));
you'll need user_likes and friends_likes permission
I'm trying to make a fql multy query using the PHP SDK. This is my code
try {
$fql = array(
"query1" => "SELECT uid2 FROM friend WHERE uid1 = me()",
"query2" => "SELECT name, url, pic FROM profile WHERE id IN (SELECT uid2 FROM #query1)"
);
//$fql = "SELECT uid2 FROM friend WHERE uid1 = me()";
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api( array(
'method' => 'fql.multiquery',
'query' => $fql,
) );
} catch ( FacebookApiException $e ) {
error_log( print_r( $e->getMessage(), true ) );
$user = NULL;
}
And this always returns an exception with no message
[04-May-2012 20:22:26 UTC] PHP Notice: Undefined property:
FacebookApiException::$getMessage in C:\Program Files
(x86)\Zend\Apache2\htdocs\wordpress\wp-content\plugins\all-in-one-event-calendar\lib\plugins\A1ecFacebookConnectorPlugin.php
on line 120 [04-May-2012 20:22:26 UTC]
i'm obviously doing something wrong, what could that be?
Ok i found how to do this, you must use queries as a parameter, not query
try {
$fql = array(
"query1" => "SELECT uid2 FROM friend WHERE uid1 = me()",
"query2" => "SELECT name, url, pic FROM profile WHERE id IN (SELECT uid2 FROM #query1)"
);
//$fql = "SELECT uid2 FROM friend WHERE uid1 = me()";
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api( array(
'method' => 'fql.multiquery',
'queries' => $fql,
) );
} catch ( FacebookApiException $e ) {
error_log( print_r( $e->getMessage(), true ) );
$user = NULL;
}
Your problem is you are trying to call $e->getMessage which does not exist. Your code on line 120 should read:
error_log( print_r( $e, true ) );
If you have problems with the multiquery, you could do this as a single query:
$fql = "SELECT name, url, pic FROM profile WHERE id IN
(SELECT uid2 FROM friend WHERE uid1 = me() )";
$user_profile = $facebook->api( array(
'method' => 'fql.query',
'query' => $fql,
) );
I've been able to get a query running like this three SELECTs deep. Four SELECTs seems to be too much.
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`
I have a fql query like this:
SELECT uid,page_id,type,profile_section,created_time FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ;
Is there any way to get only the results where page_id = XXXXXX?
Because the page_id is not indexable.. and i was hoping for a way to filter it.
I guess i found a great solution that works for me to get friends that are not pagefans.
$facebook_result = $this->facebook->api(array(
'method' => 'fql.multiquery',
'queries' => array(
'friends_liking_page' => 'SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND page_id = ' . $page_id,
'result' => 'SELECT uid, name, pic FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() AND NOT (uid2 IN (SELECT uid FROM #friends_liking_page)))'
)
));