我有 facebook 应用程序作为状态更新发布到其用户时间轴。我正在使用下面的代码来启动并向所有用户发布消息,但我的问题是在所有移动设备(iphone 和 BB、三星)上“通过名称”发布。
帖子出现在 feed 墙上,就好像用户自己而不是应用程序一样。
<?PHP
require_once '../scripts/config.php';
require_once '../inc/facebook.php';
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => 'true',
));
$dbh = new PDO('mysql:dbname='.$db_name.';host='.$db_host.';charset=utf8', $db_username, $db_password );
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlid = "SELECT SQL_CALC_FOUND_ROWS * FROM offline_access_users";
$sqlmsg = "SELECT message FROM fb_messages WHERE msg_id = (SELECT MAX(msg_id) FROM fb_messages WHERE sent = 'No')";
try {
$userid = $dbh->prepare($sqlid);
$userid->execute();
$id = $userid->fetchAll(PDO::FETCH_COLUMN, 1);
$msg = $dbh->prepare($sqlmsg);
$msg->execute();
$txt = $msg->fetchColumn();
}
catch(PDOException $e)
{
echo $e->getMessage();
die();
}
$counter = 0;
foreach($id as $fbid){
$counter++;
$body = array(
'access_token' => $access_token,
'app_id' => $fb_app_id,
'from' => $fb_app_id,
'message' => $txt,
'display' => "touch",
'redirect_uri' => "http://mydomain.com",
'link' => "",
'picture' => "",
'name' => "",
'caption' => "",
'description' => "",
);
$batchPost=array();
$batchPost[] = array('method' => 'POST', 'relative_url' => "/".$fbid."/feed", 'body' => http_build_query($body));
try {
$multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST');
$poststs = "Sent Successfully";
}
catch(FacebookApiException $e){
echo $e->getMessage();
error_log($e);
die();
}
}
unset($batchPost);
$dbh = null;