0

我有 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;
4

1 回答 1

0

您使用的是什么 $access_token?您在哪里生成 $access_token?$access_token您使用的是哪个?

帖子的创建者(通过...)是创建该帖子的人$access_token- “发件人”将始终是 Facebook 帐户的所有者,无论您在其中放置什么。

于 2013-03-12T20:59:07.470 回答