Facebook的SDK状态/页

问题描述:

你好,我创建了一个API直接发布,它在我的脸书上的配置文件工作得很好,当我尝试在我的页面发布状态时,状态是好的,帖子在游客出版物中发生了什么我做 ?Facebook的SDK状态/页

我看着Facebook Graph API,这似乎是一个错误..你可以绕过使用Curl ..?

PS /我编辑的信息页ID,应用程序ID,秘密应用

预先感谢您的帮助 史蒂芬妮

public function statutPage(){ 

    $fb = new Facebook([ 
     'app_id' => 'my app id', 
     'app_secret' => 'my app secret', 
     'default_graph_version' => 'v2.8', 

    ]); 

    $pageID='my page id,; 
    $token='A_VALID_USER_ACCESS_TOKEN'; 

    $attachment = [ 
     'access_token' => $token, 
     'message' => 'Premier message auto', 
     'name' => 'Première publication sur facebook', 
     'caption' => 'Legend sous le tire', 
     'link' => 'https://www.la-programmation.surleweb-france.fr', 
     'description' => 'Description du lien', 
     'picture' => 'https://www.google.fr/images/srpr/logo11w.png' 
    ]; 


    try { 
     $response = $fb->post('/'.$pageID.'/feed/', $attachment); 

    } catch(FacebookAuthorizationException $e) { 
     echo 'Graph retourne une erreur: ' . $e->getMessage(); 
     exit; 
    } catch(FacebookSDKException $e) { 
     echo 'Facebook SDK retourne une erreur: ' . $e->getMessage(); 
     exit; 
    } 

    $graphNode = $response->getGraphNode(); 

    echo 'Posté su Facebook avec l\'id: ' . $graphNode['id']; 

} 
+0

请编辑您的问题以提供一些'代码样本** **和**提供您想要实现的场景。同时查看Facebook Graph API文档本身。可能需要提供替代参数以达到您想要的效果。 –

+0

_“我看着Facebook Graph API,看起来这是一个错误” - - 废话。事实上,你没有仔细阅读文档。 https://developers.facebook.com/docs/graph-api/reference/v2.8/page/feed#publish – CBroe

+0

感谢您的回复,我阅读并重新阅读了文档,但这不适用于网页...在配置文件没有问题!目前我还没有找到解决方案发布一个页面上的状态... –

apparanlty下面的代码只对“用户配置文件“而不是”页面“。如果您想了解如何处理页面,请查看Facebook SDK v5 Post as Page on Wall给出的答案!


但是他这样说,Reading the Facebook PHP Developers Docs发布到对图形API 5.0饲料,我看到他们使用FacebookRequest对象,然后执行方法execute就可以了。然而它返回一个GraphObject - 这似乎deprecated in versions higher than 4

他们还提到一定要在您登录自动发布的帐户上拥有publish_actions权限。从facebook /feed/ SDK docs

参考PHP SDK代码(在url向下滚动到 '出版')的图形API 5.0 - 它返回一个GraphObject - 这似乎deprecated in versions higher than 4。 - 我编辑使用getGraphNodehttps://developers.facebook.com/docs/php/FacebookRequest/5.0.0所述的示例。

/* PHP SDK v5.0.0 */ 
/* make the API call */ 
$request = new FacebookRequest(
    $session, 
    'POST', 
    '/me/feed', 
    array (
    'message' => 'This is a test message', 
) 
); 
$response = $request->execute(); 
$graphNode = $response->getGraphNode(); 
/* handle the result */ 

可选地,它们也提到使用图形API直接链接到Publish with Graph API

+0

*类GraphObject *包Facebook * *弃用5.0.0 GraphObject已重命名为GraphNode –

+0

很遗憾,这似乎是一个错误/ miscommunication在[facebook的文档出版](https://developers.facebook.com/docs/graph-api/reference/v2.8/user/feed#publish)然后,确实它[不赞成使用5.0](https ://developers.facebook.com/docs/php/GraphObject/5.0.0) –

+0

@StéphanieCaumont尝试在'$ response'上使用'getGraphNode'方法,详见https://developers.facebook.com/docs /php/FacebookRequest/5.0.0 - 我编辑了答案。 –