Skip to content

Instantly share code, notes, and snippets.

@imvaskii
Last active February 18, 2016 13:34
Show Gist options
  • Select an option

  • Save imvaskii/1bda3d5c794e1e1f36a5 to your computer and use it in GitHub Desktop.

Select an option

Save imvaskii/1bda3d5c794e1e1f36a5 to your computer and use it in GitHub Desktop.
Get facebook page's public feed
<?php
function fetchUrl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
// You may need to add the line below
// curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$feedData = curl_exec($ch);
curl_close($ch);
return $feedData;
}
function graph_scrapper() {
$profile_id = PROFILE_ID;
//App Info, needed for Auth
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
//Retrieve auth token
$authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={$app_id}&client_secret={$app_secret}");
$json_object = fetchUrl("https://graph.facebook.com/{$profile_id}/feed?{$authToken}&?fields=full_picture");
$decode_feed = json_decode($json_object);
return $decode_feed;
}
function get_latest_post() {
$page_feeds = graph_scrapper();
$latest_feed = $page_feeds->data[0];
$single_feed = fetchUrl("https://graph.facebook.com/" . $latest_feed->id);
$decode_single = json_decode($single_feed);
return $decode_single;
}
function get_feed_picture($single_feed, $type = 'normal') {
/* https://graph.facebook.com/{object_id}/picture?type=normal
Where type can be : thumbnail, normal, album. */
return 'https://graph.facebook.com/' . $single_feed->id . '/type=' . $type;
}
function get_all_post() {
//Get feeds between 3 months
$param = array();
$param['until'] = strtotime(date('Y-m-d H:i:s'));
$param['since'] = strtotime(date('Y-m-d H:i:s', strtotime("-3 months", strtotime($param['until']))));
$page_feeds = graph_scrapper($param);
foreach ($page_feeds as $feed):
?>
<div class='content-facebook'>
<p>
<a href="<?php echo $feed->link; ?>">
<img width="150" height="116" alt="facebook-img-placeholder" src="<?php echo $feed->picture ?>" class="alignleft size-full wp-image-49">
</a>
<?php echo $feed->message; ?>
</p>
<p>&nbsp;</p>
<p><a target ="_blank" href="https://facebook.com/<?php echo $feed->id; ?>">Read More</a></p>
</div>
<?php
endforeach;
}
@polyakoff
Copy link
Copy Markdown

Is there any Public Feed API token available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment