Get Facebook application subscribers - iphone

Let's suppose I have a Facebook application with ID: XXXXXX
Is there a way to get its subscribers who are already in my friends list?

You can do this with an FQL query like this:
SELECT name, uid FROM user WHERE
uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
AND is_app_user = 1
You can only get this information from a user who is currently authenticated with your app.

Related

Get relationship (friend, friend of friend) between two Facebook ids by facebook api

How can I check for the relation between two facebook ids.? i.e friend, friend of friend or there is no relation. By fql or graph api methods(anything).
I know how to get the friend list, mutual friends of facebook id. But I want a proper method which can give the relation between two Facebook ids. I have Googled a lot but didn't get anything related to my problem.
SELECT uid2 FROM friend WHERE uid1 = me() AND uid2 = {YOUR_FRIEND2_ID}
With this FQL query you can check if give ID is a friend of currently logged in user. It'll return an empty array if given users are not friends. Facebook does not give you friends of a friend, so you can't go beyond the logged in user.
To read the friend table you need
any valid access_token to retrieve friends of the current session user
This is the only user that this table can be queried for, the friends of friends cannot be retrieved.
Facebook offical documentation on friend FQL table
I got solution by checking with fql queries.
//$target_id=id of user to check relationship
//$source_id=logged in user
$query="SELECT uid, name, work FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = $target_id AND uid2=$source_id)
ORDER BY name";
$user_info=$this->facebook->api(array('method'=>'fql.query',
'query'=>$query));
if(!empty($user_info))
{
$degree='friend';
}
else {
$query="SELECT uid, name, work FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid2 FROM friend WHERE uid1 = $target_id) AND uid2=$source_id)
ORDER BY name";
$user_info=$this->facebook->api(array('method'=>'fql.query',
'query'=>$query));
// we can check friend-of-friend for app user friends
if(!empty($user_info)) {
$degree='friend-of-friend';
}
else{
$degree='none';
}
}
Please answer if anyone knows any simple method.

get list of facebook users who are using specific application using FQL

I am trying to fetch following case using FQL
If few users have authorized "Application A" then is it possible to know that currently how many users are using that "Application A" ( users those are not friends of each other)
So far i tried following FQL , but following query gives only information of those users who are
friends of each other and using the same application , but what about other users who are not friends ?
SELECT uid, name, pic_square
FROM user
WHERE is_app_user=1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
You can't get a listing of your application's users from the API. If you need this, you should maintain your own database of users and reference that.
You can also check if any particular user is a user of your application by requesting /USER_ID/permissions?fields=installed with your application access token.
You can also check if a user's friends are users of your application by requesting the same field on the friends connection (for example, /USER_ID/friends?fields=installed). In this case, the USER_ID must be a user of your application or you won't be able to access their friends list.
is_app_user on the user table when requesting friends returns this data.
SELECT uid,is_app_user FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
or...
SELECT uid,is_app_user FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
Which is a bit tighter - only returning those users in-app.
You can't get total number of users who have installed application, but you can get daily, weekly and monthly users with simple query:
SELECT daily_active_users, weekly_active_users, monthly_active_users
FROM application WHERE app_id = APPLICATION_ID
Note: this will work for any application (not just applications user connected to)
SELECT uid FROM user WHERE uid IN ( SELECT uid2 FROM friend
WHERE uid1 = '549483876' ) AND is_app_user = 1

Can't lookup all friends of xxxxxxxxx. Can only lookup for the logged in user (xxxxxxxxx)

I have a facebook application from where I get the friends list of the connected user's friends.
It works because i get only the friends list of my friends who have authorized my application
Here are the queries :
"app_friends":"SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1"
"potential_people":"SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid FROM #app_friends)"
It worked fine until today, when I have realized that some of my friends don't authorize me to see their friends. When i m going to see their profile page, i can't see his friends.
So i get the following FQL error : Can't lookup all friends of xxxxxxxxx. Can only lookup for the logged in user (xxxxxxxxx), or friends of the logged in user with the appropriate permission
How can I specify that I want to see the list of the friends of my friends who have authorized my application AND AUTHORIZE ME TO SEE THEIR FRIENDS.
For example I have thougth about something like this :
"app_friends":"SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1 AND can_access_friends = 1"
What do you think ?

get some data of user's friends - Facebook / FQL

I'm creating an app where user will be able to select some of his friends then the app will do some job on the selected friends.
My question is =->
Can I directly write this FQL?
SELECT uid, name, pic_square FROM user WHERE uid = $friendUID
Or Do I need to write something like this?
SELECT uid, name, pic_square FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) and UID = $friendUID
http://developers.facebook.com/docs/reference/rest/fql.query/
it showed that both are correct
Both queries are same.
1. SELECT uid, name, pic_square FROM user WHERE uid = $friendUID
2. SELECT uid, name, pic_square FROM user WHERE
uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) and UID = $friendUID
In 1st query, you are directly accessing data by directly Friends Id.
In 2nd query, you are checking uid is also friend or not and then accessing data.
You can use 1st query to check any user's data though he/she might not be your friend. For uid, name, pic_square there is no any requirement that user is your friend or app user. You can get that information of any Facebook user.

Get friend's gender in a Facebook application

While developing a Facebook application I got the friendlist of a user by
$friends = $facebook->api('/me/friends');
But I only got to know the name and Facebook Ids of the friends : http://developers.facebook.com/docs/reference/api/FriendList
Is there any way to get the gender of a friend?
One way to do so is to get the user's gender (since it is publicly available) given the user's facebook Id (which I have got using the friend list)
Is it really possible to do the above thing.
If not is there any other way?
for reference : http://developers.facebook.com/docs/reference/api/user
A quick way with Graph API
$facebook->api('me/friends?fields=id,name,gender,installed&access_token=[ACCESS_TOKEN]");
http://developers.facebook.com/docs/reference/api/FriendList = a persons fiend lists (plural) - eg: Limited Profile
What you want to do is get the ID from graph.facebook.com/me/firends and then do a graph.facebook.com/ID for the gender. But of course that ends up being a lot of requests if you need it for all of their friends.
For those cases you can use FQL query: http://developers.facebook.com/docs/reference/fql/
You can adopt following query from their documentation:
SELECT uid, name, pic_square FROM user WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
Here name and gender of the current users friends:
SELECT uid, name, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())