I have an app in which I want to check my users' online presence. Right now, when I check, it tells me everyone is offline.
The users grant user_online_presence and offline_access (plus a few other) permissions to the app. Then I store the access token. I am able to access any information I need at any time except for the online presence.
To get the online presence, I first set the access token:
$facebook->setAccessToken($user['AccessToken']);
Then I query Facebook:
$fql = "SELECT uid, name, online_presence, status FROM user WHERE uid = ".$user['FacebookID'];
$param = array('method' => 'fql.query', 'query' => $fql, 'callback' => '');
$fqlResult = $facebook->api($param);
When I check the results, I get the id, name, and status, but everyone is listed as offline, even me when I know I'm online and active:
[online_presence] => offline
Any help getting this working would be greatly appreciated. Thank you all for your time.
I used this FQL query sucessfully :-
SELECT name,online_presence FROM user WHERE uid
IN (SELECT uid2 FROM friend WHERE uid1 = me())
to get all the online friends. Got output as "idle","active" and "offline". All values of which were absolutely correct.
There are 2 permits
user_online_presence, for the user
friends_online_presence, for friends
http://developers.facebook.com/docs/reference/api/permissions/
online_presence is for chat online, not facebook online
The user's Facebook Chat status. Returns a string, one of active,
idle, offline, or error (when Facebook can't determine presence
information on the server side). The query does not return the user's
Facebook Chat status when that information is restricted for privacy
reasons.
Also, I ran fql?q=SELECT name, online_presence FROM user where uid IN (Select uid1 from friend WHERE uid2=me()) and it listed my friend's online status fairly accurately. Only a very few were incorrect. Maybe that's due to a lag in the facebook update system, or maybe they're caching the information for too long, etc.
Related
recently I create an application that uses facebook login.
I'm not storing the users data, but I'd like know the users facebook id.
How can I get the facebook id of the users that have installed my application?
Thanks.
Sadly, you cannot, you need to have your own database that saves that kind of data (everytime someone logs into the application with Facebook save his ID into your own database).
This is FQl Query:
$facebook->api(array('method' => 'fql.query', 'query' => "SELECT uid FROM user WHERE is_app_user = '1' AND uid IN (SELECT uid2 FROM friend WHERE uid1 = '" . $user_id . "');"));
The documentation for the user and friend queries are here:
http://developers.facebook.com/docs/reference/fql/user/
http://developers.facebook.com/docs/reference/fql/friend/
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.
When I access the list of my friends using the URL https://graph.facebook.com/me/friends?access_token=... I can see the list of my friends. I can do this programmatically as well.
Now, when I take the ID of any of my friends and replace it with "me" in the above URL, and paste the URL in the browser, I can see my friend's friends. I am unable to do this programmatically because it is giving me an HTTP 400 ERROR.
Does anyone know why this is possible by pasting the URL and not programmatically?
You can not get the "friends of friends" using the facebook api.
For example, try the simple /me/friends with the Graph API Explorer, it should work fine.
Then, take one of the ids there and try the same with FRIEND_ID/friends and you should get this:
{
"error": {
"message": "(#604) Can't lookup all friends of FRIEN_ID. Can only lookup for the logged in user or the logged in user's friends that are users of your app.",
"type": "OAuthException",
"code": 604
}
}
The error itself is very straight forward and explains exactly what the problem is.
As for why that translates into a 400 error code for you is unclear.
Edit
You can't see the "friends of friends" in the browser as well, the reason that it works for you (probably) is that the user(s) you check the friends for (USER_ID/friends) installed the app that the access token belongs to, from the way you got to that url I assume that the app is the "Test_console".
How to check? Copy the access token from the url (USER_ID/friends?access_token=xxxxx), go to the Facebook Debugger and paste the token in the text field and click "Debug", it will show you info regarding the application.
The user you checked it for probably has that app "installed", if you check it for other users you will get that error when you get to a user who does not have that app "installed".
I hope this clarifies it for you.
I got friends of friends(limited) who are using application. 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.
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) )";
It needs following requirements:
Your friend needs to be using application.
Permission from application read_stream, publish_stream, publish_checkins.
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
The question is:
need a php script put on cron - it will mail me facebook user friends status (online or not). Found two variants:
1. using fql query $result = $facebook->api(array(
'query' => "SELECT name,online_presence FROM user WHERE uid IN (
SELECT uid2 FROM friend WHERE uid1 = me())",
'method' => 'fql.query'));
2. using xmpp. Logging to jabber facebook chat and get user presence from it.
But the question is - who to make it using only users facebook login and password (without secret facebook key, application id).
Just define the user name, password and the script will fetch the friends status.
The only way to do what you're trying to do without using the API (FQL or Graph) or XMPP (Jabber) would be to try and act like a browser to scrape facebook pages (which technically is against their TOS).