I'm working on a script for post a message on a visitors wall. The visitor can enter there own message in a form en then send it to facebook.
index.php:
<form name="form" method="post" action="wall.php">
<textarea name="t_update" cols="50" rows="5" id="t_update" >message</textarea><br>
<input type="submit" name="Submit" value="Post To Your facebook Account!">
</form>
This sends "t_update" to "wall.php". The wall.php script is working fine I tested it with static text. but when I try to insert the "t_update" text into the var $APP_MSG it's empty when send to facebook. This is the complete wall.php script.
wall.php:
<?php
/** FB APP DATA **/
$FB_APPID = "Facebook app id";
$FB_SECRET = "Facebook secret code";
/** MSG DATA **/
$APP_MSG = ($_POST['t_update']); // post message
$APP_MSG_LINK_TITLE = "Title";
$APP_MSG_LINK = "www.domain.com";
global $ch;
$code = $_REQUEST["code"];
$error = $_REQUEST["error"];
$returnurl = "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];
function facebook_curl_request($url,$params=array(),$post = false){
global $ch;
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11');
curl_setopt ($ch, CURLOPT_HEADER, false);
if($post == true){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
$response = curl_exec ($ch);
$temp = json_decode($response,1);
if(isset($temp["error"]) && is_array($temp["error"])){
echo $temp["error"]["type"]."<br>";
echo $temp["error"]["message"]."<br>";
echo "--------------------------------------------";
curl_close ($ch);
exit;
}
return $response;
}
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $FB_APPID . "&redirect_uri=" . urlencode($returnurl) . "&scope=publish_stream,email";
header("Location: $dialog_url");
}
if(!empty($error)){
echo $_REQUEST["error"]."<br>".$_REQUEST["error_reason"]."<br>".$_REQUEST["error_description"];
}else{
if(!empty($code)){
/** CREATE TOKEN **/
$ch = curl_init();
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $FB_APPID . "&redirect_uri=" . $returnurl
. "&client_secret=" . $FB_SECRET . "&code=" . $code;
$token = facebook_curl_request($token_url);
$tarr = explode("&",$token);
list($token_name,$token) = explode("=",$tarr[0]);
/**GET USER INFO**/
$graph_url = "https://graph.facebook.com/me?".$token_name."=".$token;
$user = json_decode(facebook_curl_request($graph_url),1);
$userid = $user["id"];
/* POST TO WALL **/
$graph_url = "https://graph.facebook.com/".$userid."/feed";
$params = array(
$token_name => $token,
"message" => $APP_MSG,
'name' => $APP_MSG_LINK_TITLE,
'link' => $APP_MSG_LINK
);
$response = facebook_curl_request( $graph_url, $params, true);
list($userid,$postid) = explode("_",$response);
echo "<html><head></head><body>Bedankt voor het posten op facebook!</body></html>";
curl_close ($ch);
}
}
?>
I've tried everything can anybody point me in the right direction???