ユーザー入力を求めて画像を生成し、画像リンクを 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"));