向Facebook群组发布新闻



*strong text*我有一个每天发布文章的网站。

我想有一个相应的Facebook组,我可以在同一时间在我的网站上发布的文章。

我使用api在twitter中设置了类似的安排。当我在我的网站上发布一篇文章时,它会自动发布标题,并通过twitter API链接回twitter。我想在我的facebook群里有一个类似的安排。

可以把我的故事转发到我的facebook群墙上吗?

编辑

好了,我已经说到这里了,不能再继续了:

步骤1:获得发布到流

的授权
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)将我的消息发送到流:

 $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;
}

代码运行时没有错误,但没有返回任何内容,也没有将任何内容张贴到墙上

任何想法?

Facebook对待页面的方式与他们对待人的方式相似,您指定一个与您的组的Page ID相关联的UID。然后只需使用Facebook的Graph API将内容发布到流中,就像您对一个人一样。

要授权,您从管理员那里获得Facebook API权限并请求manage_pages权限。

您需要的所有信息都包含在这里:https://developers.facebook.com/docs/reference/api/#impersonation.

(Ctrl+F Page Login获取有关授权更新到页面的更多信息)

最新更新