Facebook api帖子通过“我的应用程序名称”

时间:2013-03-12 20:52:02

标签: php android ios facebook-graph-api jquery-mobile

我有facebook应用程序,将其用户时间轴发布为状态更新。我使用下面的代码启动并将消息发布给所有用户,但我的问题是所有移动设备上的“通过名称”帖子(iphone& BB,Samsung)。该帖子显示在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;

1 个答案:

答案 0 :(得分:0)

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

帖子的创建者(来自...)是创建$access_token的人 - “来自”将永远是Facebook帐户的所有者,无论你放在那里。