Facebook API php - 将新闻发布到facebook群组

问题描述:

* strong text *我有一个每天发布文章的网站。Facebook API php - 将新闻发布到facebook群组

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

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

是否有可能将我的故事转发到我的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将页面视为与他们对待人类相似的页面,您需要指定一个与您的组的页面ID相关联的UID。然后,只需使用Facebook的Graph API将其发布到流中,就如同您对某个人一样。

要授权,您可以从管理员处获得Facebook API许可并请求manage_pages权限。

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

(Ctrl + F Page Login了解更多关于授权更新到页面的信息)。