Finding a users friends and determining if they have the app - facebook

So, after looking around the two solutions ive seen are:
1) Using the graph API
me/friends?fields=installed
2) Using FQL
SELECT uid FROM user WHERE uid in (SELECT uid1 FROM friend WHERE uid2=me()) AND is_app_user
SELECT uid FROM user WHERE uid in (SELECT uid1 FROM friend WHERE uid2=me()) AND NOT is_app_user
Using the graph API i'm always met with permissions issues and cannot find what permission i need to request in order to access it. And the FQL solution seems to always return false.
So I'm left wondering if theres something simple that im missing in order to get this working,or whether or not these methods are outdated and theres a better way.
Thanks in advance
EDIT 1
I should mention that i am working from a C# api

Using PHP SDK you can get the friendlist by using:
$facebook->api(array('method' => 'friends.getAppUsers'));

As for the permissions: You need to have the email permission to get the friends list with installed flag in it.
I can guess that you are following the normal login flow. like,
1)opening session
2)requesting read permissions (user_info etc.)
just add the "email" permission in read permissions as well and you shall get this installed flag.
3) and then you can use either the graph api or FQL, results should be similar.

Related

FQL - can't get link info from user - 'Request Failed' error

This should be an easy one. All I want it the user's profile url.
I've tried the following FQL:
SELECT profile_url FROM standard_user_info WHERE uid = me()
but get the Request Failed error. I'm using the Graph API Explorer / FQL Query and have the latest Access Token.
Basically I'm looking for the FQL equivalent to this Graph API call:
https://graph.facebook.com/me?fields=link
Thanks for the help
If you read the documentation properly, you'll notice that-
standard_user_info requires the APP_ACCESS_TOKEN, instead of USER_ACCESS_TOKEN. You can get the App Access Token from the Access Token Tool, for the testing.
You can get the information about the authorized app users only.
So, you can test it like this-
SELECT profile_url FROM standard_user_info WHERE uid = USER_ID
Note: Don't use me() (since you are using the app access token now which didn't recognize me()), instead use you ID)

FQL Error: requires extended permission: read_stream

Today I started get some strange FQL Error.
FQL query: *SELECT target_id FROM connection WHERE source_id = user_id1 AND target_id = user_id2*
*SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = "user_id")*
FQL Response (Error): Error: Requires extended permission: read_stream
What is it???
Help.
According to their Change Log, on 2011-09-18, Facebook pushed this update:
FQL connection table now requires read_stream permission. (rE435878)
I had the same problem. I was only using the connection table to get a list of friends, so I was able to change to the friend table to pull the info I needed.
Stuff like this is what makes Facebook Platform a hostile development environment.
Looks like facebook has changed some of the required permissions for some actions this night. The same happened to me. You need to ask for read_stream permissions. For more information refer here
P.S: You might need to remove the application from your profile and add it again with the new permissions

What function in Social Graph loads mutual friends so fast?

I am making a Facebook application for which I require the mutual friends of the logged in user. The Old API friends.getMutualFriends does the work but it is very slow. I was wondering if there is any other way of getting the list of mutual friends.
Moreover, applications like SocialGraph load very fast, so what functions are they using to get hold of the mutual friends so quickly?
I found the solution :)
With friends.getMutualFriends, it takes n^3 API which is a huge number. I tried areFriends as well which was no better. So I fetched the data via FQL query as follows:
//Create Query
$params = array(
'method' => 'fql.query',
'query' => " SELECT uid1, uid2 FROM friend
WHERE uid1 IN
(SELECT uid2 FROM friend WHERE uid1= $match)
AND uid2 IN
(SELECT uid2 FROM friend WHERE uid1= $match)",
);
//Run Query
$result = $facebook->api($params);
It takes less than a second to get the mutual friends !
If you are concerned about speed, I would suggest calling the information once and finding a way to cache the data. Facebook now provides you with the ability to do so "legally". You may use memcached for this sort of thing or save it temporarily in a database.
As of September 2011, there is a new api call for this:
This week we added a connection for the User object that allows you to
get the list of mutual friends between two users. To use it, just get
an access token for the current user and issue a GET request to:
https://graph.facebook.com/me/mutualfriends/FRIEND_ID
Platform Updates: Operation Developer Love

How to get facebooks friends who are all single using either PHP sdk or FQL?

In my application I'm trying out to list only the friends who are all single.
I tried different methods and it didn't return proper values...
I tried the graph API but could list only all the friends irrespective of their relationship status.
i tried $facebook->api("/$user/friends?relationship_status='single'");
Also i tried to use FQL and fetch things up but the relationship status always return up as 'null' for even the user who have approved the applications and gave permission to access their relationship_status..
the fql query i tried is
SELECT
uid,name, relationship_status, current_location
FROM user
WHERE
uid IN (SELECT uid2 FROM friend WHERE uid1 = 2343434434234)
How can i get this done?
The problem is that you're only asking for that user's relationship status. You need to also ask for the friends_relationships permission. Once you do that, your query will work fine.

Facebook API: friends' hometown_location and current_location always empty using FQL

I've been looking at this at every possible angle and I can't make my mind around it, maybe you guys can help. I run this query to get my friend's hometown and location:
SELECT uid, name, timezone, hometown_location, current_location
FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1 = me() )
And hometown_location and current_location are always NULL, even when they shouldn't be. Using something like /me/friends?fields=hometown,location,... has the same result.
Also, querying for my own hometown_location and current_location DOES WORK. Which makes me think I don't have the permissions to access my friends' hometown & location.. but shouldn't then an error be raised, if this was the case?
Still, my app has the same permissions: user_about_me, friends_about_me, user_hometown, friends_hometown, user_location & friends_location, so I don't think this is the issue.
If I go to http://developers.facebook.com/docs/reference/api/ and click on the https://graph.facebook.com/me/friends?access_token=... link, and I append &fields=name,hometown, it works, so I know it can be done.
Any idea what could I be doing wrong?
Thanks a lot!
Manuel
For friends_hometown you need friends_hometown permission.
For current_location you need friends_location permission.
Once you ensure you have those permissions you should be able to get the data by running that query or through the Graph API - https://graph.facebook.com/FRIEND_ID?fields=hometown,location with an access_token having those permissions.
Are you using Simon Cross' interface?
https://www.simoncross.com/fb/graph/
It can help you understand what is the problem. Try to regenerate your access_token you might still use an old token which didn't have extended permissions for friend_hometown.
The API doesn't throw any kind of error in case you (or the token used) don't have permission to access the data