Facebook iOS - fql search for shortened name - iphone

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

Related

Facebook FQL Get All Posts At Location

The location_post FQL table is described as the following:
An FQL table that returns Posts that have locations associated with
them and that satisfy at least one of the following conditions:
you were tagged in the Post
a friend was tagged in the Post
you authored the Post
a friend authored the Post
So I wrote the following FQL script with the intent of getting all posts my friends and I had made at a certain location:
SELECT id, message, post_id, timestamp FROM location_post WHERE page_id=303736809701751
However, an empty data set is returned. In this particular case, I expect some of my own posts to be returned, though I have tried other place ids that should have returned friends' posts as well.
What is missing from the request, or is this a bug I should report to Facebook?
The paragraph you quoted from the doc just says that the table only contains places where yourself and friends of yours have been. It tries to explain that you will not find public users there.
A query to the location_post table does not automatically specify the concerned IDs for you. If you want to search for the places where all your friends have been, you will have to indicate all your friends. If you are only interested by a bunch of friends, just add the concerned IDs.
This should do it.
SELECT id, message, post_id, timestamp
FROM location_post
WHERE (author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
OR author_uid = me()
OR tagged_uids IN (SELECT uid2 FROM friend WHERE uid1 = me())
OR tagged_uids = me())
AND page_id = 303736809701751

Facebook FQL: using special characters when searching by friends name

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

How to get Facebook Friends Age in Android

I am writing an app in which i am fetching list of facebook friends along with their names, profile pics and birthdays, to get that i am using below query:
String query = "SELECT name, birthday, uid, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY birthday_date ASC";
and i have given these permissions:
String[] facebook_permissions = { "user_photos", "user_birthday",
"friends_birthday", "friends_photos", "read_stream",
"offline_access" };
but now i also want to show Age of my facebook friend, and i guess to get that i should use
age_range
I am also trying to get age of facebook friends by using below query but i am getting null in place of age:
String query = "SELECT name, birthday, uid, pic_square, age_range FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY birthday_date ASC";
Age range is not how old is a person, but, as facebook documentation says:
containing min and max for the age range; Possible age ranges are
13-17, 18-20, and 21+; max is not set if the age is 21+
Why don't you calculate how old friends are using birthday and today dates? This can be done in a very simple way using native Calendar.
I'd recommend you to use new facebook API too.

FQL Get all of my friends' checkins?

This seems to be impossible as of now .. can anyone give me a suitable query or a set of queries that can do this? Basically, I need ALL my friends' checkins: Ones they've checked in by themselves, Ones in which they've checked with a picture, Ones in which a user who is not my friend tagged them in.
My first attempt was this:
SELECT checkin_id, author_uid, page_id, coords, tagged_uids, timestamp FROM checkin WHERE (author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) OR author_uid=me()) ORDER BY timestamp DESC LIMIT 50
But this doesn't include checkins with pictures.
My second attempt was this:
SELECT id, author_uid, app_id, timestamp, tagged_uids, page_id, page_type, coords, type FROM location_post
WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1=me())
But like the WHERE clause suggests, we're only looking for checkins which were created by a friend, but not ones in which my friends are tagged.
My next attempt was this:
SELECT id, author_uid, app_id, timestamp, tagged_uids, page_id, page_type, coords, type FROM location_post
WHERE tagged_uids IN (SELECT uid2 FROM friend WHERE uid1=me())
But it just returns an empty data set as it probably should.
So short of submitting 500 odd queries, one for each of my friends, is there a way to do this?
Any pointers are much appreciated!
Thanks,
Teja
we can also use following FQL to get friends checkins and checkins in which friends are tagged:
SELECT checkin_id FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) OR tagged_uids IN (SELECT uid2 FROM friend WHERE uid1 = me())
Does this need to be in FQL or would the Graph API not suffice for this?
/me/friends?fields=checkins, although very slow (warning: with lots of friends this could timeout completely), returns me a list of my friends with an array of their recent checkins (and those checkins' likes, comments, etc)
You could also break it up into batches of friends for better performance:
/?fields=checkins&ids=[CSV LIST OF FRIENDS TO CHECK]
I was recently trying to solve the same problem and finding that using the graph via /me/friends?fields=checkins was too slow to be usable and sometimes times out completely.
I did just stumble across the search function though, which seems to do exactly what I (and perhaps you) want.
To quote the facebook documentation:
Checkins: https://graph.facebook.com/search?type=checkin (This request
returns you or your friend's latest checkins, or checkins where you or
your friends have been tagged; currently, it does not accept a q=
parameter.)
There's tons more examples here under Search: https://developers.facebook.com/docs/reference/api/

Facebook current UID with FQL

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/