PHP zeige letzten Facebook Page Post

Einfache Funktion um den letzten Post einer Facebook Page anzuzeigen. Benötigt wird ein Access Token der gewünschten Facebook Page.

< ?php 

/*	Hole letzten Facebook Page Post
*	@param Null
*	return array: title,image,text,link
*	
*	Funktionsaufruf:
*	
*	$post = get_last_facebookpost();
*	echo $post['title'];
*	echo $post['image'];
*	echo $post['text'];
*	echo $post['link'];
*/
function get_last_facebookpost(){
	$token = '123456789123456789123456789';
	$page = 'Webgreat.de';
	header('Content-Type: text/html; charset=utf-8');
	$data = file_get_contents("https://graph.facebook.com/".$page."/promotable_posts?access_token=".$token);
	$result = json_decode($data);
	$latest_post =  $result->data[0];
	$latest_post_title = $latest_post->name;
	$latest_post_image = $latest_post->picture;
	$latest_post_text = $latest_post->description;
	$latest_post_link = $latest_post->actions[0]->link;
	
	$facebook_last_post['title'] 	= $latest_post_title;
	$facebook_last_post['image'] 	= urldecode($latest_post_image);
	$facebook_last_post['text'] 	= $latest_post_text;
	$facebook_last_post['link'] 	= urldecode($latest_post_link);
	return $facebook_last_post;
}

?>