Facebook API php-将新闻项目发布到Facebook组
*强文本*我有一个每天发布文章的网站 我想有一个相应的Facebook群组,我可以在我的网站上同时发布文章 我已经使用api在twitter上建立了类似的安排。当我将一篇文章发布到我的网站时,它会自动发布标题并通过twitter API链接回twitter。我希望我的facebook群组也有类似的安排 是否可以将我的故事转发到我的facebook群组墙 编辑 好吧,我已经走到这一步了,没有更多了: 步骤1:获得发布到流的授权Facebook API php-将新闻项目发布到Facebook组,php,facebook,Php,Facebook,*强文本*我有一个每天发布文章的网站 我想有一个相应的Facebook群组,我可以在我的网站上同时发布文章 我已经使用api在twitter上建立了类似的安排。当我将一篇文章发布到我的网站时,它会自动发布标题并通过twitter API链接回twitter。我希望我的facebook群组也有类似的安排 是否可以将我的故事转发到我的facebook群组墙 编辑 好吧,我已经走到这一步了,没有更多了: 步骤1:获得发布到流的授权 if ($fp = fopen('https://graph.face
if ($fp = fopen('https://graph.facebook.com/oauth/access_token?client_id=XXXXXXXXXX&client_secret=XXXXXXXXXXXXtype=client_cred&scope=publish_stream', 'r')) {
$content = '';
// keep reading until there's nothing left
while ($line = fread($fp, 1024)) {
$content .= $line;
}
$tokens = explode("access_token=",$content);
// do something with the content here
$auth_token = $tokens[1];
fclose($fp);
} else {
// echo" an error occured when trying to open the specified url";
}
步骤2:使用我的授权代码将我的消息发送到流(我已选择使用cURL):
代码运行时没有错误,但是没有返回任何内容,也没有发布到墙上
有什么想法吗?Facebook对待页面的方式与对待他人的方式类似,您可以指定一个UID,该UID与组的页面ID关联。然后,只需使用Facebook的Graph API发布到流中,就像你对一个人一样 要进行授权,您需要从管理员处获得Facebook API权限,并请求
manage\u pages
权限
此处包含您需要的所有信息:
(Ctrl+F页面登录
了解有关授权更新页面的更多信息)
$message="This will be a post on my groups wall.";
$url = "https://graph.facebook.com/my_app_id/feed";
$data = array('message' => $message, 'auth_token' => $auth_token);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
print "Nothing seems to have happened";
}
else
{
print $buffer;
}