在Facebook页面墙上张贴页面 [英] post as page on facebook page wall
问题描述
我想要做什么 / p>
当我在我的网站上添加文章时,我想在Twitter和Facebook上发布更新。它在Twitter上工作,但是我有Facebook的问题。
我下载了使用OAuth的facebook.php。
我的问题
当我发布一个简单的文本,它的工作正常,它显示为按页面发布想要的。但是,当我想发布一个带有缩略图,链接,标题和描述的文本时,它会被发布,就像我的个人帐户是否将此更新发布到我的页面的墙上。
这是我的简单文本的代码(我请求上面的acces_token):
$ post = array('access_token' => $ token,'message'=>'我的消息');
尝试{
$ res = $ facebook-> api('/ mypage / feed','POST',$ post);
print_r($ res);
} catch(异常$ e){
echo $ e-> getMessage();
}
以下是错误的代码:
$ post = array('access_token'=> $ token,
'message'=>'我的消息',
'picture' ="'http://www.website.com/picture.jpg',
'link'=>'http://www.website.com',
'caption'=> ;'test caption',
'description'=>'test description',
'from'=>数组('name'=>'页面名称','id'=> 'page id'),
);
try {
$ res = $ facebook-> api('/ mypage / feed','POST',$ post);
print_r($ res);
} catch(异常$ e){
echo $ e-> getMessage();
}
Facebook API没有很好的记录,但我搜索到的地方不要问你这个问题..但我没有找到任何解决方案。
非常感谢帮助我。
<?php
/ **
*编辑您定位的页面ID
*和给你的粉丝的消息!
* /
$ page_id ='PAGE_ID';
$ message =我是一页!;
/ **
*此代码只是PHP-SDK< http:// github中的example.php脚本
*的片段。 COM / Facebook的/ PHP-SDK /斑点/主/示例/使用example.php>
* /
require'../src/facebook.php';
//创建我们的应用程序实例(将其替换为您的appId和密码)。
$ facebook = new Facebook(array(
'appId'=>'app_id',
'secret'=>'app_secret',
));
//获取用户ID
// $ user应该是页面admin
$ user = $ facebook-> getUser();
if($ user){
try {
$ page_info = $ facebook-> api(/ $ page_id?fields = access_token);
if(!empty($ page_info ['access_token'])){
$ args = array(
'access_token'=> $ page_info ['access_token'],
'message'=> $ message,
'name'=>'我的墙上标题/标题在这里',
'caption'=>'小标题在这里',
' link'=>'http://www.mywebsite.org',
'description'=>'Wall Post Details Here',
'picture'=>http:// www .mywebsite.org / images / logo.gif,
);
$ post_id = $ facebook-> api(/ $ page_id / feed,post,$ args);
}
} catch(FacebookApiException $ e){
error_log($ e);
$ user = null;
}
}
//根据当前用户状态,需要登录或注销url。
if($ user){
$ logoutUrl = $ facebook-> getLogoutUrl();
} else {
$ loginUrl = $ facebook-> getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
}
?>
I've read many other topics about this subject but I didn't find something helpful.
What I want to do
When I add an article on my website, I'd like to post an update on Twitter and Facebook. It's working for Twitter, but I have an issue with Facebook.
I downloaded the facebook.php which uses OAuth.
My issue
When I post a simple text, it works fine, it's displayed as posted by the page as wanted. But when I want to post a text with a thumbnail, a link, a caption and a description, it's posted as if my personal account was posting this update onto my page's wall.
Here is my code for the simple text (I requested the acces_token above):
$post = array('access_token' => $token, 'message' => 'My message');
try{
$res = $facebook->api('/mypage/feed','POST',$post);
print_r($res);
} catch (Exception $e){
echo $e->getMessage();
}
Here is the wrong code:
$post = array('access_token' => $token,
'message' => 'My message',
'picture' => 'http://www.website.com/picture.jpg',
'link' => 'http://www.website.com',
'caption' => 'test caption',
'description' => 'test description',
'from' => array('name' =>'Page name', 'id' => 'page id'),
);
try{
$res = $facebook->api('/mypage/feed','POST',$post);
print_r($res);
} catch (Exception $e){
echo $e->getMessage();
}
The Facebook API is not well documented but I've searched everywhere not to ask you this question .. But I don't find any solution.
Thanks a lot for helping me.
Benjamin
Hoping you have the following permissions (publis_stream,manage_pages, offline_access) and access_token, try the following code
<?php
/**
* Edit the Page ID you are targeting
* And the message for your fans!
*/
$page_id = 'PAGE_ID';
$message = "I'm a Page!";
/**
* This code is just a snippet of the example.php script
* from the PHP-SDK <http://github.com/facebook/php-sdk/blob/master/examples/example.php>
*/
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'app_id',
'secret' => 'app_secret',
));
// Get User ID
// $user supposed to be page admin
$user = $facebook->getUser();
if ($user) {
try {
$page_info = $facebook->api("/$page_id?fields=access_token");
if( !empty($page_info['access_token']) ) {
$args = array(
'access_token' => $page_info['access_token'],
'message' => $message ,
'name' => 'My Wall Post Header/Title Here',
'caption' => 'Small caption here',
'link' => 'http://www.mywebsite.org',
'description' => 'Wall Post Details Here',
'picture' => "http://www.mywebsite.org/images/logo.gif",
);
$post_id = $facebook->api("/$page_id/feed","post",$args);
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
}
?>
这篇关于在Facebook页面墙上张贴页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!