Facebook fql search by first letter of the name - facebook

Hello guys i'm trying to do a fql query that search the friends by first letter of the name, i did this query but doesn't show me the right result.
In this case i tried to get all my friends with the first letter "g" but CONTAINS doens't do what i'm looking for. There is another way?
SELECT uid , first_name, last_name FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me()) AND ( CONTAINS('g')
AND strpos(lower(name),lower('g')) >=0 ) ORDER BY first_name ASC

The problem is with your usage of strpos(). You query will retrieve all your friends having a letter 'g' in their name. And, I think there's no point of using a contains() here.
This query will work fine for your task:
SELECT uid , first_name, last_name FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me()) AND
strpos(lower(first_name),lower('g')) = 0 ORDER BY first_name ASC
As you can see here, I'm using strpos(lower(first_name),lower('g')) = 0. This will retrieve only those friends having 'g' as the first letter in their first name.

Related

FQL not returning photos tagged with friend

I am trying to use FQL to get a list of my own photos that have friends tagged in them. The friends are specified by their name or part of their name. i.e input from a text box
So far I have come up with the FQL below, which almost works, but...
Can anyone tell me why the first query returns a list of records but the second query returns nothing? the only difference between the two is the second one searches on just part of the person's name i.e "laura" vs "lau"
FQL 1
SELECT object_id, src_big, src_big_width, src_big_height, aid
FROM photo
WHERE object_id in (
SELECT object_id
FROM photo_tag
WHERE subject in (
SELECT uid
FROM user
WHERE (strpos(lower(name),"laura") >=0 )
AND (uid in (SELECT uid2 FROM friend WHERE uid1 = me()) ))
)
AND owner = me()
FQL 2
SELECT object_id, src_big, src_big_width, src_big_height, aid
FROM photo
WHERE object_id in (
SELECT object_id
FROM photo_tag
WHERE subject in (
SELECT uid
FROM user
WHERE (strpos(lower(name),"lau") >=0 )
AND (uid in (SELECT uid2 FROM friend WHERE uid1 = me()) ))
)
AND owner = me()
It looks like Facebook has a bug in its system so strpos doesn't work as expected in sub queries. As a workaround you could try splitting it into two queries - one that finds list of id-s:
SELECT uid
FROM user
WHERE (strpos(lower(name),"lau") >=0 )
AND (uid in (SELECT uid2 FROM friend WHERE uid1 = me()) )
And a second one that uses this list:
SELECT object_id, src_big, src_big_width, src_big_height, aid
FROM photo
WHERE object_id in (
SELECT object_id
FROM photo_tag
WHERE subject in (111,222,333,444,555)
)
AND owner = me()

How can I use more than 1 column in ORDER BY in FQL?

I've got a question about FQL: Is it possible to do an ORDER BY on more than one column?
The following FQL query works:
SELECT uid,first_name,last_name
FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = 123)
ORDER BY last_name
However, this one doesn't:
SELECT uid,first_name,last_name
FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = 123)
ORDER BY last_name, first_name
It returns:
"error": {
"message": "(#601) Parser error: unexpected ',' at position 122.",
"type": "OAuthException",
"code": 601
Is this working as intended, or am I doing something wrong?
This isn't possible. I recently filed a documentation bug that explains FQL ORDER BYcan only contain one column. So it is indeed working as intended.
https://developers.facebook.com/bugs/148360015351840

Get friend without friend app user with FQL or Graph

Now I get random 19 friend in my facebook with fql query : SELECT uid, pic_square, name FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1 = me() ) ORDER BY rand() limit 19, But now I don't know, how to get 19 friends not in friendappuser.
I already found anwser for my question:
SELECT uid, pic_square, name
FROM user WHERE uid IN (SELECT uid2 FROM friend
WHERE uid1 = me()) AND is_app_user = 0 ORDER BY rand() limit 19

Facebook API - FQL - How to read places where my friends were tagged

How to read places where my friends were tagged ?
I found sth like this, but this example is not working for me .
or do I have to check piece by piece
SELECT page_id, author_uid FROM location_post WHERE xxfriendIDxx IN tagged_uids ??
{
"my_friends":"SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() ORDER BY rand() LIMIT 100)",
"their_locations":"SELECT page_id, author_uid FROM location_post WHERE tagged_uids IN (SELECT uid FROM #my_friends) LIMIT 100",
"those_places": "SELECT page_id, name, location FROM page WHERE page_id IN (SELECT page_id FROM #their_locations)"
}
Thx for help!
The below query will give you all the places that your friends have been tagged.
SELECT page_id, name, location FROM page WHERE page_id IN (SELECT page_id FROM location_post
WHERE author_uid IN
(SELECT uid2 FROM friend WHERE uid1=me()))
Make sure you have enabled the friends_photos, friends_checkins and friends_status permissions.
I couldn't get any data either until I changed your their_locations sub-query to this:
SELECT page_id, author_uid FROM location_post WHERE
tagged_uids IN (SELECT uid FROM #my_friends)
OR author_uid IN (SELECT uid FROM #my_friends)
LIMIT 100
It still isn't returning some location tagged posts that I can see using /FRIEND_USERNAME/locations.
There are other friends I know who post location tagged items all the time, but their privacy settings must be inhibiting these from being returned by the API.
You need the user_tagged_places permission. API V-4
<?php
//permissions array
echo '<li> Login With Facebook</li>';
//call field
echo '<pre>' . echo $graphObject['tagged_places'] . '</pre>';
?>

Upcoming Friends BirthDay List from Facebook

How can I get the list of upcoming b'days of my friends with user id, name and birth day. I am using following fql query to get the friends b'day list.
query = "SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY birthday_date DESC LIMIT 50 ";
Change your FQL query to :
SELECT uid, name, birthday_date FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())
AND birthday_date >= "06/08"
AND birthday_date <= "06/15"
ORDER BY birthday_date ASC
This will constraint the date to the next week, ordered by the next available birthday.