Alex
Alex

Reputation: 1619

Get Facebook Status from Fan Page using API

I've been trying to get the most recent Facebook Status for a fan page via the API for a while now and can't seem to get what I'm after. I'm really trying to avoid using RSS for it. I can get the full list from the feed via https://graph.facebook.com/174690270761/feed but I want only the last status posted by the page admin, not by anyone else.

Is their an easy way to get it without having to authenticate?

Thanks in advance

edit: https://graph.facebook.com/174690270761/statuses seems to be what I'm looking for but I need an OAuthAccessToken for this but can't see how to without involving the user, as I'm trying to access through my own credentials/application

Upvotes: 4

Views: 9780

Answers (3)

Alex
Alex

Reputation: 1619

I finally found out that this doesn't have to be done through the API, or require any authentication at all.

Basically you can access the data via a JSON feed:

$pageID = "ID of Page" //supply the Id of the fan page you want to access
$url = "https://graph.facebook.com/". $pageID ."/feed";
$json = file_get_contents($url);
$jsonData = json_decode($json);

foreach($jsonData->data as $val) {
    if($val->from->id == $pageID) { //find the first matching post/status by a fan page admin
        $message = $val->message;
        echo $message;
        break; //stop looping on most recent status posted by page admin
    }
}

Upvotes: 2

Niksac
Niksac

Reputation: 770

Facebook has changed the api and now requires you to provide an access token. You can use Facebooks PHP sdk for that but i found a much quicker way to go:

<?
$appid = '1234567890';
$secret = 'db19c5379c7d5b0c79c7f05dd46da66c';
$pageid = 'Google';

$token = file_get_contents('https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='.$appid.'&client_secret='.$secret);
$feed = file_get_contents('https://graph.facebook.com/'.$pageid.'/feed&'.$token);

print_r(json_decode($feed));
?>

Update 15/12/12 app access tokens nosist of the id and secret now - use this request:

$feed = file_get_contents('https://graph.facebook.com/Saxity/feed?access_token='.$appid.'|'.$secret);

Upvotes: 13

NG.
NG.

Reputation: 22914

I don't think there's a good way to do this. You can process the JSON pretty easily though from the looks of it. You can limit the number of results by using the since query parameter. For instance:

https://graph.facebook.com/174690270761/feed?since=last%20Monday

You can also use limit on that, but I don't think that filters by user. If the administrator is the only one allowed to post, then you may be able to get away with using limit=1.

Upvotes: 1

Related Questions