这是我的代码:
$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();
}
此时我可以在我的代码中的任何地方打印$ message的内容,除了 try block 之外我得出的结论与Facebook会话有关。当会话建立并执行 try block 时,由于某种原因$ _POST ['content']的值;消失了,我收到了错误:
未定义的索引:/var/www/html/submit.php中的内容
我知道 $ session 从 getSessionFromRedirect 获取会话信息,我很确定何时发生此重定向,$ _POST ['content']不会t继续进行那次会议。
我的问题是:如何添加来自表单元素(textarea)的信息,将其分配给变量并将该值传递给 $ postRequest = new FacebookRequest($ session,'POST','/我/ feed',$ message); ,以便我的应用显示此类自定义消息?
谢谢!
这是index.php代码:
<!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>