2017-02-26 210 views
0

你好,我創建了一個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

感謝您的回覆,我閱讀並重新閱讀了文檔,但這不適用於網頁...在配置文件沒有問題!目前我還沒有找到解決方案發佈一個頁面上的狀態... –

回答

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 - 我編輯了答案。 –