通过与Facebook的QUOT后的API;我的应用程序名称和QUOT; [英] Facebook api post via "my application name"
问题描述
我的Facebook应用程序发布到其用户的时间线作为状态更新。我使用下面的code发起并张贴讯息给所有用户,但我的问题是,在所有移动设备的帖子通过名称(iphone&安培; BB,三星)。
的帖子出现在饲料壁,如果用户贴吧自己不是应用程序。
< PHPrequire_once'../scripts/config.php';
require_once'../inc/facebook.php';$ Facebook的=新的Facebook(阵列(
APPID=> $ fb_app_id,
'秘密'=> $ fb_secret,
'饼干'=> '真正',
));$胸径=新PDO('MySQL的:数据库名='$ DB_NAME';主机='$ DB_HOST';字符集= 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消息从fb_messages WHERE MSG_ID =(SELECT MAX(MSG_ID)FROM fb_messages WHERE发送='没有');尝试{ $用户id = $ dbh-> prepare($ SQLID);
$ userid->执行();
的$ id = $ userid->使用fetchall(PDO :: FETCH_COLUMN,1); $味精= $ dbh-> prepare($ sqlmsg);
$ msg->执行();
$ TXT = $ msg-> fetchColumn();
}赶上(PDOException $ E)
{
回声$ E->的getMessage();
死();
}$计数器= 0;的foreach($ id作为fbid $){$柜台++;$身体=阵列(
ACCESS_TOKEN'=> $的access_token,
APP_ID'=> $ fb_app_id,
'从'=> $ fb_app_id,
'消息'= GT; $ TXT,
'显示'=> 触摸,
REDIRECT_URI'=> http://mydomain.com
'链接'=> ,
'图片'=> ,
'名'=> ,
'标题'=> ,
'描述'=> ,
);$ batchPost =阵列();$ batchPost [] =阵列('方法'=>'POST','relative_url'=>中/\".$fbid.\"/feed,体= GT; http_build_query($体));尝试{
$ multiPostResponse = $ facebook-> API('?批='urlen code(json_en code($ batchPost)),'POST');
$ poststs =已成功发送
}赶上(FacebookApiException $ E){
回声$ E->的getMessage();
error_log中($ E);
死();
}
}
未设置($ batchPost);
$胸径= NULL;
什么$的access_token您使用的?哪里的你产生$的access_token?哪个 $的access_token
您使用的?
后(通...)的创造者是谁创造了 $的access_token
- 从永远是Facebook帐户的所有者不管你放置在那里。
I have facebook application that posts to its users timeline as status update. I am using the code below to initiate and post the message to all users, but my issue is the post "via name" on all mobile devices (iphone & BB, Samsung).
The post appears on feed wall as if the user posted it himself not the application.
<?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;
What $access_token are you using? where did the you generate the $access_token?Which $access_token
are you using?
The creator of the post (the via...) is whoever created that $access_token
- the "from" will always be the owner of the Facebook account regardless of what you place there.
这篇关于通过与Facebook的QUOT后的API;我的应用程序名称和QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!