FB.api(
{
method: 'fql.query',
query: 'select uid,name from user where uid in (select uid2 from friend where uid1 ='+me.id+') AND current_location='+me.location.name
},function(data) {
alert(data);
}
iam trying to get the friends based on the current user location.But this query is not working? Is there any possible way to write this as a single query?
I need to loop all the datas to check the current location else ,but it takes time for checking it.So iam looking for single query to get the datas? Could any one help me with it?
This is just an idea,
firstly your application requires user_location and friends_location as permissions.
Why don't you modify your query to something like this
FB.api(
{
method: 'fql.query',
query: 'select uid,name,current_location from user where uid in (select uid2 from friend where uid1 ='+me.id+')
},function(data) { alert(data);
}
The idea is to get current_location of user and user's friends and then do your filtering.
Hope this helps
Related
Hi i want to get list of my fabebook friend ids with paging of 100 users.
The problem is that if i set hte FQL to
NSString *fqlString = #"SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) LIMIT 300";
It returns me as expected the only first 300 users in the table with out any reference to next page.
Result: {
data = (
{
uid = 1519xxx;
},
{
uid = 9806xxx;
}
....
);
}
if i request friends with [FBRequest requestForMyFriends] it returns me all of my friends and additionaly a paging key with the url object for next page.
The question is how can i tell with FQL to give me lists of 100 users with paging to next 100 users.
The Graph API returns paging links; FQL does not. So you’d have to do that yourself, by making another query including an OFFSET parameter.
I am trying to find the friends with most mutual friends with me.
public function topThreeMutualFriends() {
$count;
$query='select uid1 from friend where uid1 in (select uid2 from friend where uid1=me()) and uid2 in (Select uid2 from friend where uid1=me()) and uid1!=uid2';
$result = $this->api(array('query' => $query , 'method' => 'fql.query'));
if(!$result)
throw new exception("No Mutual Friends");
else{
foreach ($result as $uid)
$count[$uid['uid1']]++;
arsort($count, SORT_NUMERIC);
$i=0;
foreach($count as $key=>$uid){
$topthree[$i++]=$key;
if($i==3)break;
}
return array($topthree,$count);}
}
In the above code an exception is raised stating:"This API call could not be completed due to resource limits"
I tried giving all the permissions, and the query works fine in the fql tester.
What could be the possible reason??
That's pretty complex code. Why not just let FQL find your top three friends with the most mutual friends?
$query = 'SELECT uid, name, mutual_friend_count
FROM user WHERE uid IN
(SELECT uid1 FROM friend WHERE uid2 = me())
ORDER BY mutual_friend_count DESC LIMIT 3';
The possible reason is the error message you pasted, your query is too expensive in terms of the resources needed from Facebook's side.
Break it up into smaller queries and do that instead. For example, fetch the list of friends in one call, split the list into smaller chunks, and check the mutual friends count for the batches in separate calls.
I am executing this query in FQL [#"SELECT likes,message,actor_id FROM stream WHERE source_id = %lld limit 50", _session.uid]. It is giving result well but I want to fetch my friends name also. I don't want to execute query within loop to fetch friends name from their profile. If it is possible in multiquery then which type of query I will have to write?
I use this code:
NSString* fql = [NSString stringWithFormat:#"SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = %lld)", session.uid];
Hope it can give you a hint.
I'm trying to properly understand the syntax for Facebook's fql.query. The context for this query is to get all the mutual friends between two users. Using an example of "user1 = dusty24" and "user2 = april1991" what would the values for the following vars be?
uid1
uid2
source_uid
target_uid
It's pretty safe to assume that 'uid1 = dusty24' and 'uid2 = april1991' but what the heck are the values for 'source_uid' and 'target_uid'?
FB.api(
{
method: 'fql.query',
query: 'SELECT uid1 FROM friend WHERE uid1 IN (SELECT uid2 FROM friend WHERE uid1=source_uid) AND uid2=target_uid'
},
function(response) {
console.log(response);
}
}
I took a quick read through the documentation, it tells us uid1 is the user id of the first user of the pair and uid2 is the second user of the pair. These are fields from the table. You don't change these in the query. You would end up with source_uid and target_uid be the user ID's of each of those people.
Assuming your query works correctly. You would end up looking something like this. Note: you would need to get the user id of your two users before hand.
SELECT uid1 FROM friend
WHERE uid1 IN
( SELECT uid2 FROM friend WHERE uid1={*dusty24 uid*} )
AND uid2={*april1991 uid*}
I am trying to achieve the following via Facebook's Multiquery FQL, get a list of all Fan Page Events that i am 'Attending'.
I have the below logic, and have tried to implement something similar with the FQL statement below.
get list of all events created by / from a Fan Page (using specific id)
get a list of all my (the users) events attending
Match eid's from event_member FQL Table
If they match ids, and rsvp_status is equal to attending
display result.
FQL Multi
{"query1":"SELECT eid FROM event WHERE
eid IN (SELECT eid FROM event_member
WHERE uid
=$fanpageID)","query2":"SELECT rsvp_status FROM event_member WHERE
uid = $uidAND eid IN
(SELECT eid FROM #query1)"}
I know the statement is incorrect, but i am struggling on trying to do this. I have achieved this via Graph API using a very messy set of foreach loops in my PHP code.
Using a single multiquery FQL statement would be far more efficient.
Any suggestions would be great.
EDIT
Problem im having now, is ifaour's FQL statement works within the FQL Query console (Returns Results), however when i run the following, and empty array is returned.
When i dissect the statement to just ( SELECT eid FROM event WHERE creator =$fanPageID) the FQL Console highlights that eid in non indexable.
Here is my PHP
function usersEventsPoints($uid,
$facebook, $fanpageID){
$events = "SELECT eid FROM event WHERE creator=$fanpageID AND eid
IN (SELECT eid FROM event_member WHERE
uid=$uid AND rsvp_status =
\"attending\")";
$eventsAttendance = $facebook->api(array(
'method' => 'fql.query',
'query' =>$events, ));
$eventsAttendingcount = 0;
foreach
($eventsAttendance as $eventsAttendanceFetch) {
if($eventsAttendanceFetch['eid'] == true){
$eventsAttendingcount++;
}
}
return $eventsAttendingcount;
}
Blockquote
Any Ideas?
It's a very simple task:
SELECT eid FROM event WHERE creator = $fanpageID AND eid IN (SELECT eid FROM event_member WHERE uid = me() AND rsvp_status = "attending")
This will return all events' Ids that are created/owned by the page that has $fanpageID id and you are a member in (me()) and your status is attending.
EDIT:
You are looping the returned array just to get the count?! you can simply use:
$eventsAttendingcount = count($eventsAttendance);
Also make sure that the user you are matching, has authorized your application and granted you the correct permission!
I'm not sure I understand what the problem is - I ran your FQL statement and it returns a list of events and then your RSVP status?
On another note, why not use the events.get method. You pass in the UserId and it will display the event information for you. You can filter by RSVP status.
Just checked and the events.get method is in the process of being deprecated.
You should use the new Graph API which gives you a list of attendees for your event:
http://developers.facebook.com/docs/reference/api/event
You get the list of attendees by using
https://graph.facebook.com/EVENT_ID/attending
If you want to get the next 10 events of the facebook logged user where events are set a attending then you can build your Swift query like this:
let graphPath = "/me/events?limit=10&type=attending&since=now"
let params = ["fields": "id, name, category, start_time, end_time, timezone, updated_time, type, attending_count, owner, place"]
let request = GraphRequest(graphPath: graphPath, parameters: params, accessToken: accessToken, httpMethod: .GET, apiVersion: apiVersion)
request.start {}