Facebook News Feed Api

joshl_1995 1 Tallied Votes 551 Views Share

Hello Community,
I have been looking for a facebook news feed api, i couldn't find one. All i could find is bits of script for construct my own news feed api.

So thats what i did and i thought i might share the script with you it's a bit messy but it works.

Here is how t use it:
1. Goto https://www.facebook.com/developers and login.
2. Click "Create New App". 6ecbba8247b18cca50e467f8ce0063b1
3. Enter an app name i've used "NewsFeed" make sure it's valid then leave app namespace blank and web hosting un-ticked then click "Continue". 6cf853eeb15bfc42f6953659d6a43676
4. Then copy and paste the script:

Then to get your access token goto https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=PUT_APP_ID_HERE&client_secret=PUT_APP_SECRET_HERE

I hope you found this tutorial easy to follow, but if you have any question just leave a comment below and i will get back to you.

	$curl = curl_init("https://graph.facebook.com/".$FB_PAGE."/feed?limit=".$FB_LIMITS."&access_token=".$FB_ACCESSTOKEN);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
	$FBdata = curl_exec($curl);
	foreach (json_decode($FBdata)->data as $post) {
		if (!empty($post->id)) {
			$temp1 = strpos("D".$post->created_time, "D") + strlen("D");
			$result = substr("D".$post->created_time, $temp1, strlen("D".$post->created_time));
			$dd = strpos($result, "T");
			if ($dd == 0) { $dd = strlen($result); }
			$finalDate = explode("-", date("j-M-Y", strtotime(substr($result, 0, $dd))));
			$msg = "";
			if (empty($post->message)) { $msg = $post->story; } else if (!empty($post->message)) { $msg = $post->message; } else { exit(); }
			$ptID = explode("_", $post->id);
			echo "<p><a href='https://www.facebook.com/".$FB_PAGE."/posts/".$ptID[1]."' target='_blank'>".$finalDate[0]." ".$finalDate[1].", ".$finalDate[2]."</a> by ";
			if ($post->from->name == $FB_PAGENAME) { echo "<a href='http://facebook.com/".$FB_PAGE."' target='_blank'>".$FB_PAGENAME."</a>"; } else { echo $post->from->name; }
			echo "<br>".preg_replace(array('/(?(?=<a[^>]*>.+<\/a>)(?:<a[^>]*>.+<\/a>)|([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+))/iex',
			'/<a([^>]*)target="?[^"\']+"?/i', '/<a([^>]+)>/i', '/(^|\s)(www.[^<> \n\r]+)/iex', '/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+) (\\.[A-Za-z0-9-]+)*)/iex'),
			array("stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\">\\2</a>\\3':'\\0'))",'<a\\1', '<a\\1 target="_blank">', "stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\">\\2</a>\\3':'\\0'))",
			"stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))"), nl2br($msg))."</p><hr/><br>";