I'm interested in rendering only a list of friends of a certain sex. I'm using the query below, but not having any luck:
"SELECT name FROM user WHERE sex= $sex AND uid IN ( SELECT uid2 FROM friend WHERE uid1= $fb_uid )"
From what I understand, it should work because AT LEAST ONE of the constraints is indexable. Am I missing something?
Here are my thoughts:
Make sure that the user have the right permission, I guess it's read_stream
Make sure the user you are matching is the logged in user (maybe using me() instead)
the sex field accepts only: male and female
Related
I'm using FQL to search for friends. This is one example that works:
SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strpos(lower(name),'hugo') >=0
Now, I want to make a search that returns all friends containing "anto":
Example names (notice the special character: ó):
"antónio manuel"
"antonieta maria"
How can I achieve this? Is there any replace function in FQL?
Note: I don't want to use something like:
(...) AND (strpos(lower(name),'anto') >=0 OR strpos(lower(name),'antó') >=0)
thank you
I am using the Facebook iOS library to access users' friends' data via facebook query language. To search for specific friends by name, I am using the following NSString:
[NSString stringWithFormat:#"SELECT pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strpos(lower(name),'%#') >= 0 ORDER BY name", name]
So the query would look something like this:
SELECT pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strpos(lower(name),'firstname lastname') >= 0 ORDER BY name
I'm running into problems when the friends set their first names on facebook to nicknames - the query returns no results. For example, if I query Benjamin Button, but he has set his name on facebook to Ben Button, I'm out of luck.
How can I modify this query to allow for nicknames like this? Or at least to allow for some sort of wildcard operator at in the middle of the name?
Thanks!
James
I am using FQL to get the list of friends
$fql = select uid, name, work_history,
education_history, current_location
from user where uid IN (select uid2
from friend where
uid1=FACEBOOK_USER_ID);
does this query returns same friend sequence all the time or it is different in few cases.
suppose list returns : Friend1,friend2,friend3 .... etc
So does it return the same sequence all the time or not?
Please let me know if any further detail required or if the problem is not clear.
-deepak
I'd take all doubt out of the equation and just add an ORDER BY:
SELECT uid, name, work_history, education_history, current_location
FROM user
WHERE uid IN (select uid2 from friend where uid1=<FACEBOOK_USER_ID>)
ORDER BY uid
It appears that they come back in sequential order based on the user id. So if you had three friends with the user ids 111111, 222222, and 3333333, they would be returned in that order.
With THAT said, I wouldn't rely on this behavior. Even if it never changes, it is probably bad practice to assume it will always be that way. It's a much better practice to get the data, then order it on your end to your needs. That way you know it is always in the order you want even if the ordering on Facebook's end changes.
I'm trying to develop a search for people by name feature using the Facebook API.
I'm trying this FQL query:
SELECT uid, username, name, pic_square FROM user WHERE strpos(name, 'Alfredo Artiles') >= 0
But I get an "Your statement is not indexable. The WHERE clause must contain an indexable column." error.
I also tried to add a "and uid > 0" condition, but that didn't work too.
Any idea?
SELECT uid, username, name, pic_square FROM user WHERE contains('Alfredo Artiles')
I have no idea why it works, as it violates the "at least and indexable field in WHERE", but it does.
EDIT: this is where I read it: link
later edit
Ok, sorry for the mistake regarding strpos, I didn't remeber it existence last time i checked the fql docs. The thing about it is that it can be used just in certain cases. You need to have a primar indexable column in your where clause and a second condition with strpos (at least this is how I succeded using it). For example:
SELECT actor_id, message FROM stream WHERE source_id = me() AND strpos(message, 'stuff') > 0 limit 50
I hope this clarifies a little bit the confusion with this function.
U need to specify the uid in where clause fetch details in facebook user table. we don't get the the all user details.here get the details of currently logged in user
"SELECT name FROM user WHERE uid IN(SELECT uid2 FROM
friend WHERE uid1 = me()) AND strpos(name,'Alfredo Artiles') >=0"
YES, YOU CAN!!!
Try to search in profile table, instead of user table. In profile table, the name field is indexable, so your statement would have to change only a bit:
SELECT id, username, name, pic_square FROM profile WHERE contains('alfredo artiles') and type='user'
Contains is not case-sensitive while strpos is. You could still use lower and strpos, but you would also have the problem of special characters. Contains is the solution.
You can find all fields of profile table in facebook doc:
Hope it helps!
How can i get my current UID with FQL.. i want to save traffic and requests with getting the the friends of a user with fql.multiquery
"query1": GET NEED MY USERID
"query2":"SELECT uid, first_name, last_name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=MYUSERID) order by first_name"
should return my friends! getting users with friends.get and then users.getInfo needs 2 requests and is not optimal...
Thank you
Your first query should be entirely unnecessary, as Facebook always provides the uid to an application via the fb_sig_user parameter (POST or GET). I'm not sure what kind of FQL query you could use to get a uid based on some other form of information. There's no sessions table or anything available to FQL (available tables are listed here).
For multi-queries however, I'm fairly certain that this page describes exactly what you need to do, but I'll throw some code together in the way that I would do it.
If it was a PHP app, and I wanted to do this server side, I would create a couple of JSON-formatted strings and send them as a query as follows:
$fql= '{
"userinfo":"SELECT uid FROM user_standard_info WHERE first_name=\'zombat\'",
"friends":"SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid FROM #userinfo)}"
}';
$res = $facebook->api_client->fql_multiquery($fql);
print_r($res['userinfo']);
print_r($res['friends']);
This should produce a dump of your query results.
Assuming you have your current uid available from the fb_sig_user parameter (which you should), then your problem should be solved by something like this:
$fql= '{
"friends":"SELECT uid2 FROM friend WHERE uid1='.$your_uid.',"
"friendinfo":"SELECT * FROM standard_user_info WHERE uid IN (SELECT uid2 FROM #friends)"
}';
$res = $facebook->api_client->fql_multiquery($fql);
Note: You may want to have a careful look at some of the queries you're trying to do. Many tables, such as friend, can only be used if you're dealing with a logged-in user.
The function me() returns your user id in FQL.
To get the list of your friends, you can use:
SELECT uid, first_name, last_name
FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
You can find the documentation of this here: http://developers.facebook.com/docs/reference/fql/