facebook graph api..get friends of friends - facebook

I am using the FB graph api to get a list of my friends' friends using:
https://graph.facebook.com/<id>/friends?access_token=<token>
Now the weird thing is that this works for some of my friends and does not work for some others. Could somebody tell me why this is happening and a possible fix?
In cases where it does not work, I get the following message:
"Can't lookup all friends of YYYYYY.
Can only lookup for the logged in user (XXXXX), or
friends of the logged in user with the appropriate permission"
And I repeat, I AM ABLE to get friend lists of some of my friends using the above URL.
What permissions are being mentioned here?

Privacy permissions.
As a user, I control who can see my friends list. If I select "Friends only" then only my friends can see my list, not "friends of friends"
Log into facebook, on the upper right click on Account -> Privacy settings,
then Click on "View Settings" under "Connecting on Facebook"
"See your friends list" is what controls this.
Edit: Sorry, had to think about that for a minute.
You can see your friend's friends via the standard Facebook web UI. Your app is not you. Even though you've granted the app access to your account, your friends have not. In that case, you're not going to get back your friend's friends unless they have it set to "Everyone". Your app is not a friend of a friend.
I believe that's the reason. The other reason could be that their API is renown for being buggy. You could always open a bug report on http://bugs.developers.facebook.net/ and if my supposition is correct, someone will let you know.

I got friends of friends(limited). I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.
We can get friends of friends those are app users.
Try by this fql query.
$fb_id= user id whose friends of friends required.
$query="SELECT uid, name, work_history FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = $fb_id ) and is_app_user=1) )";
$user_info=$facebook->api(array('method'=>'fql.query',
'query'=>$query));

Indeed. It's all http requests. But if I click on the link to show John's friends, facebook lists them, and if I use the graph api and a token, it doesn't. Either way it's me asking, but the api is inconsistent.

Related

Some facebook friends' birthdays returning as null but I have the correct API permissions

I'm tring to get my friends' birthdays in my app and some of them are null. I thought that those people don't have a birthday set, but they actually do.
My fql query is:
SELECT uid,name,birthday_date FROM user WHERE uid IN (SELECT uid2 from friend where uid1=me())
The birthdays are also null when I request /me/friends?fields=birthday
My access token has the friends_birthday permission set.
I also tried with birthday instead of birthday_date in the FQL query. Same result.
I imagine that this happens because they opted out somehow, but I don't know how.
Is there an alternate solution to actually get their birthdays from facebook?
It's also possible to remove the ability of apps to access your data when your friends use them, this option will prevent the current session user from seeing some information about their friends via the API, even if that information is accessible on Facebook.com
This setting is in the privacy settings, at https://www.facebook.com/settings/?tab=privacy, under Ads, Apps and Websites -> 'How people bring your info to apps they use' and looks like this:
{edit} you can test this for yourself with test users, it's the most likely reason assuming the birthdays are visible to you in the frontend
These people might have set their Birthdays visible to only themselves or only some restricted friends. This is an option available if we try to edit our Birthday by its side. That can cause it is not available to your query by app.

How to get the count of FB friends my friends have?

Now my app is seeking the following permissions from user.
user_about_me,user_birthday,email, friends_about_me,friends_relationships
I'm getting the friends of the current logged in user and their relationship status. Is there any way to get the total count of FB friends for each one of them (i.e. No of FB friends my friends have) . I don't need the friends list but its enough to get the total no of FB friends a FB user have.
Is that possible? I know that if the user haven't authorized the app we couldn't find any information. But i guess the no of friends a FB user has may be a public data!!(unless he has privacy setting over them also)..
Is that possible using any FQL queries?
I have found a solution myself. Its possible to use the FQL to get the friends count.
There is a friend_count field against the user table.
SELECT uid, name, friend_count
FROM user
WHERE
uid IN
(SELECT uid2 FROM friend WHERE uid1=me())
The above query will retrieve all my friends with their names and their friend_count.

How to get user's facebook pages and apps list after authentication?

After a user install my application to his/her facebook page,I want to get his/her facebook pages and apps list.
I have read these documents:
http://developers.facebook.com/docs/reference/fql/application/
http://developers.facebook.com/docs/reference/fql/developer/
What is the best way to do?
Another question:
How to check if a user is my app's user?
It sounds like you haven't really looked at the documentation, but they are fairly clear questions, so...
After getting the user_likes permission you can query /me/likes to get a list of pages the user likes. A list of apps is not currently possible in the same way.
A call to /me/permissions or /me/?fields=installed will show if the current app is installed by the current user
A call to /me/accounts with the 'manage_pages' permission will show which pages and apps a user admins, but not which pages and apps they use.
You can use FQL to query this information.
select uid, name, is_app_user from user where uid in (select uid2 from friend where uid1=me()) and is_app_user=1
The user needs to allow (and be user of) your app in order to be able to authenticate though oauth.
You can list the user's pages and apps by accessing:
https://graph.facebook.com/me/accounts
or
https://graph.facebook.com/%user_id%/accounts
But you must also provide the user oauth token.

Friends of Friends/2nd degree friend's list. Facebook Graph API

I am trying to get a list of my friend's friends using the iPhone Facebook SDK.
I've tried an approach using FQL and the Graph API but I get an error in both cases:
"Can't lookup all friends of YYYYYY. Can only lookup for the logged in user (XXXXX), or
friends of the logged in user with the appropriate permission"
I've done some research and see that this functionality wasn't available through the Facebook API up until October 2010. But then radio silence. Well, it's almost 6 months later. So was this ever implemented?
I have requested all permissions I need for my app as well.
This functionality does not exist in the Facebook Social Graph API or the FQL API.
During my quest to find out how to accomplish this I found many developers who asked the same question. Some developers have been asking for this feature for over 2 years. I think the FB team may consider it a privacy of performance concern.
I have worked on it. I was able to see friends of my friend.
It needs following requirements:
Your friend needs to be using application.
Permission from application read_stream, publish_stream, publish_checkins.
Try this fql query.
$query="SELECT uid, name, work_history FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 IN
( SELECT uid FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = $fb_id ) and is_app_user=1)
)";

Getting friends of friends in FB graph API

I would like to get friends of friends via an API call and when I try to do it, I get the following exception,
{
"error": {
"type": "OAuthException",
"message": "(#604) Can't lookup all friends of .... Can only lookup for the logged in user (...), or friends of the logged in user with the appropriate permission"
}
}
The URL I am trying to access is,
https://graph.facebook.com/friend_id/friends?access_token=access_token
I am getting extended permissions which is as follows,
<fb:login-button perms="user_likes,friends_likes"></fb:login-button>
Could any one please let me know what's going wrong here? Or does it mean I can never get access to friends of friends?
Currently, there is no extended permission that allows you to view a user's friends of friends. The "*_likes" permissions just show you the Facebook pages that the users have Liked.
It might be possible for you to iteratively fetch and cache the friends of each of the user's friends, one by one, but without access tokens for each friend, you'll only be able to fetch public data.
I got friends of friends(limited). I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.
We can get friends of friends those are app users.
$fb_id= user id whose friends of friends required.
$query="SELECT uid, name, work_history FROM user WHERE uid IN (SELECT
uid2 FROM friend WHERE uid1 IN (SELECT uid FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = $fb_id ) and is_app_user=1) )";
$user_info=$facebook->api(array('method'=>'fql.query',
'query'=>$query));
#Olie:
You are fetching your friends of your friend through application. So you would need permission from your friend whose friends you want. i.e. Your friend should be using that application and accepted those permission while allowing accessing information. Otherwise you wont be able to friends of your friend. I have tested this query. And it works successfully.
"message": "(#604) Can't lookup all friends of .... Can only lookup for the logged in user (...), or friends of the logged in user with the appropriate permission"
This message explains well. Read carefully.
Hope you understand solution criteria.
You cannot get friends of friends, it is not allowed due to privacy concerns.
A workaround we have done before is to save all users friends to oure own database.
That way we could cross-reference all the different users friend-list's and at least get friends of friends who have used the application we made.
Important note, such a table would quickly grow quite seizable depending on the amount of users you get.
Count on each user having about 250-300 friends on average, so if you opt for such a solution make sure to optimize your database for it, and then it should work just great.
Got same problem, had to use old REST API to get at least mutual friends, see
http://developers.facebook.com/docs/reference/rest/friends.getMutualFriends/
You can get the friends of the current user through a Graph API call to me/friends. You will need any valid access_token, no special extended permissions, just the Basic one. There is one caveat, that user must allow you to see their friend list. So in the Privacy Settings > Connecting on Facebook there is a "See your friend list" setting. If the user has chosen a custom setting and selected say "Only Me" you will get this error.
Similarly, if the current user allows others to see their friend list, but one of the friends shuts this down due to privacy concerns then you will not be able to see any data and will get that error.
I was able to verify the scenarios I have described.
Unfortunately, I can't ask your answer specifically since I don't have experience with the FB API. However, I believe that FB allows users to hide who their friends are. If they have this set, then perhaps you won't be able to access their friends at all. I'd try to modify your code to first check what the permissions of a given user are and only then accessing their friends list if you have access to it. A bit of speculation here, though.