This is my code:
$message = $_POST['content'];
echo $message;
exit();
if ($session) {
try {
// $request = new FacebookRequest($session, 'GET', '/me');
// $response = $request->execute();
// $me = $response->getGraphObject();
// echo $me->getProperty('email');
$postRequest = new FacebookRequest($session, 'POST', '/me/feed', $message);
$postResponse = $postRequest->execute()->getGraphObject();
// uploading image to user timeline using facebook php sdk v4
//$response = (new FacebookRequest(
// $session, 'POST', '/me/photos', array(
// 'source' => new CURLFile('picture.jpg', 'image/jpg'),
// 'message' => 'User provided message'
// )
// )
//)->execute()->getGraphObject();
//if($response) {
// echo "Done";
//}
} catch(FacebookRequestException $e) {
echo $e->getMessage();
}
At this point I am able to print the content of $message anywhere in my code, except inside the try block I came to the conclusion that is has something to do with the Facebook session. When the session is establish and the try block gets executed, for some reason the value of $_POST['content']; disappears and I get the error:
Undefined index: content in /var/www/html/submit.php
I know that $session its getting the session information from getSessionFromRedirect and I'm pretty sure when this redirect happens, the $_POST['content'] doesn't get carried over that session.
My question is: How can I add information that comes from a form element (textarea), assign it to a variable and pass that value to $postRequest = new FacebookRequest($session, 'POST', '/me/feed', $message); in order for my app to display such custom message?
Thanks!
This is the index.php code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Facebook API Post</title>
<link rel="stylesheet" href="styles/styles.css">
</head>
<body>
<form action="submit.php" method="POST">
<h2>Post to Facebook!</h2>
<label for="postcontent">Post: </label>
<textarea name="content" id="postcontent" placeholder="Enter your post here..." rows="5"></textarea>
<button type="submit">Post To Wall!</button>
</form>
</body>
</html>