我有一个程序(一个应用程序),它要求用户输入然后生成图像并将图像链接发布到 FB 时间轴。现在我要做的是获取 POSTID 并将其保存到我的数据库中。所以我可以有一个记录,如果我想连接到 FB POST,我可以检索它。我怎样才能做到这一点?以下是我用于发布到 Facebook 时间线的代码。希望你能帮我解决这个问题。我第一次做这样的事情。多谢!
$http_dir = 'http://site.com/Amats/image_entry/';
$post_link = $http_dir . $img_newname;
if (!empty($name) && !empty($email) && !empty($office_id) && !empty($title) && !empty($story)) {
$save_sql = "INSERT INTO `tbl_contest` (filename, name, email, office_id, title, story, time) VALUES ('$img_newname','$name','$email','$office_id','$title','$story','$sql_date')";
$query = mysql_query($save_sql,$con) or die(mysql_error("Could not write information to the database"));
if (mysql_num_rows($con) !== 0) {
header('Location:' . $uploadSuccess.'#modal-text');
if($user_id) {
// We have a user ID, so probably a logged in user.
try {
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => $post_link,
'message' => 'Posting with the PHP SDK!'
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
// Give the user a logout link
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl( array(
'scope' => 'publish_stream'
));
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, so print a link for the user to login
$login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
echo 'Please <a href="' . $login_url . '">login.</a>';
}
}
mysqli_close($con);
}
我试着做这样的东西。但它不起作用;
$post_id = $ret_obj['id'];
$save_id = "INSERT INTO `tbl_mytable` (post_id) VALUES ('$post_id')";
$query = mysql_query($save_id,$con) or die(mysql_error("Could not write information to the database"));