<?php
$app_id = "APP_ID";
$app_secret = "APSECRET";
$post_login_url = "http://apps.facebook.com/NAMEAPP";
$code = $_REQUEST["code"];
//Obtain the access_token with publish_stream permission
if(empty($code)){
$dialog_url= "http://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url
. "'</script>");
}
else {
$token_url="https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Show photo upload form to user and post to the Graph URL
$graph_url= "https://graph.facebook.com/me/photos?"
. "access_token=" .$access_token;
$post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!','picture'=>'http://2.bp.blogspot.jpg','name'=>'NAMEAPP','description'=>'DESCRIPTION!','link'=>'http://apps.facebook.com/NAMEAPP'));
}
?>