Facebook friends online - facebook

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).

Related

How can I get the list of facebook id of users that installed my app?

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/

Retrieving Facebook Events using FQL (permissions issue)

I'm trying to retrieve all facebook events that a page that I have created, has been invited to. I created an App and following is the code I got from http://www.codeofaninja.com/2011/07/display-facebook-events-to-your-website.html:
//requiring FB PHP SDK
require 'fb-sdk/src/facebook.php';
//initializing keys
$facebook = new Facebook(array(
'appId' => '[app_id>],
'secret' => '[app_secret]',
'cookie' => true, // enable optional cookie support
));
$fql = "SELECT name, pic, start_time, end_time, location, description
FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 100001660923071 )
ORDER BY start_time asc";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
print_r($fqlResult);
Now the problem is that it works fine when the uid in the query is set to '221167777906963'(its the UID from the example code and it works wine with any app-id/secret combination) but when I set it to the uid of the page I am the owner of none of the events get returned. Is there something I'm missing? I double checked on my pages>accounts settings>apps to see if the app that I created had permission to the page and it does. Its a public page. What am I missing in the flow to give this app permission to get access to my pages events? The same query works fine if i run it in the Graph API Explorer with an access token that I generate for user_events.
I'm basically trying to understand why a particular Wordpress Plugin called FB Sync Events isn't working and the app authentication is what seems to be failing cuz the $facebook->api is returning nothing for a fql.query JUST for my page. QQ
For accessing the page's events, you might need to use a PAGE access token. Page access tokens are easy to get. For the page administrator's user access token, call Graph /me/accounts and in there will by the page along with an access token for that page. That is what is called a "Page Access Token". Then using that Page access token, call your FQL statement.
As far as I know it's no possible to display the events you have been invited to if you create a Facebook page instead of a profile. Since when you create a page you only have users who like you page. This means they can interact with the content you publish but they can't interact with you as a brand or company.
On the other hand when you create a profile you have users who are your friends and they can interact with you and the content you publish in many ways, including being able to be invited to events.

Unable to Get Correct User Online Presence

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.

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

FQL does not return post with customized location

i wrote a small FQL script that returns the latest wallposts of my fanpage. The script works fine. Until today.
The situation:
I published a wallpost with custom settings: The post is only visible to German fans.
The Problem:
My fql query ignores this "special" post.
My little PHP program looks like this
$query = " SELECT
post_id, message, created_time, attachment,action_links, privacy, type
FROM
stream
WHERE
source_id = ".$page_id."
AND actor_id = ".$page_id."
ORDER BY created_time DESC";
$param = array(
'method' => 'fql.query',
'query' => $query,
'callback' => ''
);
$result = $this->facebook->opengraph->api($param);
The nugget:
Facebook returns the status message if i call the special post like this:
https://graph.facebook.com/367501354973
(Source: http://developers.facebook.com/docs/ref … api/status)
Thanks for helping
In general, content which is demographically targeted or restricted will only be made available to a user access token for a user who meets the demographic set - check that the user you're trying to access the posts as is actually in the demographic you targeted the post at.
I got a similar problem using the grpah api:
This does NOT return the special post
https://graph.facebook.com/MYPAGE/posts?access_token=SOME_TOKEN
If I call the graph via FB-Docs (they offer a special access token, i get the special post
https://graph.facebook.com/MYPAGE/posts?access_token=22223423470867|2.qnqX1HsEaIXVr0lVHCRxiw__.3600.12913423423400-10043534534530485|4wqk8YYWXQ8bjfQj8KETz2JyWQk
Stange...
If your FQL is calling without an access_token, then the API won't return any posts that any kind of restrictions placed on them. In your example, geo gated to Germany.
The reason it's working via the Docs is that we're appending an access_token.