Reputation: 11121
I want to write a Wordpress plugin that will fetch 'updates' of my friends or pages I like on facebook.
Any code sample? I tried to look at Facebook for Websites but didn't find and example on how to get the updates.
Upvotes: 1
Views: 286
Reputation: 645
OK. Let's start by the beginning. You can do this, sure. Facebook API is growing and you can do it for a very simple way, using "FQL".
Following the code (based on the facebook example):
<?php
$facebook = new Facebook(array(
'appId' => '127375200698444',
'secret' => '3584a791118c4d8811573c8184b51385',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
$fql = 'SELECT status_id, message from status where uid=' . $user;
// Proceed knowing you have a logged in user who's authenticated.
$updates = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
} catch (FacebookApiException $e) {
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'user_status, friends_status',
));
}
The code above require an application registered at facebook (You can register on at https://developers.facebook.com/apps). Just register there and replace the appId and the secret with your values.
After all this done, you must echo the url $loginUrl to get the AuthToken of your user. With this token, you can get all the updates of him (using the fql of the example).
The Facebook type used in here is available at https://github.com/facebook/php-sdk.
I hope this helps or at least have given a path.
Status FQL Docs: http://developers.facebook.com/docs/reference/fql/status/
API Method Docs (my example was based in here): http://developers.facebook.com/docs/reference/php/facebook-api/
Upvotes: 1
Reputation: 921
I am guessing it would have to be a AJAX request from JavaScript on a set interval to check if a table has been updated, and if it has, refresh that results on the Page with AJAX. I would use jQuery for the AJAX syntax, it makes it much easier. And as for the PHP, just make it check to see if there are any changes in a table, if so, output the results in an echo
and have jQuery append the results too the page. That seems like the most reasonable way to do it
Check jQuery.com to learn jQuery ajax and interactions with PHP. Its pretty simple if you know any JavaScript or jQuery and PHP at all
Upvotes: 0