2016-08-10 60 views
1

我想建立一個腳本,當提交按鈕時將數據發佈到facebook頁面。使用捲曲發佈到一個網站的Facebook頁面

我創建了一個不過期的頁面訪問令牌,但我堅持如何構建url。在圖形API Explorer中的許多測試中不斷給我:

{ 
     "error": { 
     "message": "(#200) The user hasn't authorized the application to perform this action", 
     "type": "OAuthException", 
     "code": 200, 
     "fbtrace_id": "BYNmxVAlESA" 
     } 
    } 

我想是這樣的:?

1745650152362669 /養活消息=消息&的access_token = myaccesstoken

1745650152362669 /飼料?fields = message = message & access_token = myaccesstoken

both as POST ofcourse。

雖然我確實授予我的應用程序的權限。

就像你可以在這裏看到:

enter image description here

此令牌到期後一個小時,所以我按「在訪問令牌池打開」

enter image description here

而且點擊擴展訪問代幣:

enter image description here

我再次粘貼標誌在圖形API的探險家,但現在該頁面不再被選中: enter image description here

是這樣的方式,它應該是?

我有下面的代碼應該執行上提交帖子:

<form> 
    <input type="submit" name="submit"> 
</form> 
<? 

if(isset($_POST['submit'])){ 
    $token = 'mypageaccestoken'; 

    $attachment = array(
    'access_token' => $token, 
    'message' => $contentcr[0]['introtext'], 
    'name' => $contentcr[0]['title'], 
    'link' => $contentcr[0]['alias'].'html', 
    'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) 
    ); 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/1745650152362669/feed'); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($ch); 
    curl_close ($ch); 
} 

上面的代碼目前不會發布任何東西到我的網頁,可以有人解釋我缺少的是什麼?

+0

您缺少發佈權限。 https://developers.facebook.com/docs/graph-api/reference/v2.7/page/feed#publish – CBroe

+0

@CBroe謝謝你的工作! – twan

回答

1

用戶未授權應用程序來執行此操作

該錯誤意味着你缺少相應的權限。您需要publish_pages才能發佈(如Page),而不僅僅是manage_pages

+0

好吧,有道理,我可以在哪裏添加更多權限?創建頁面訪問令牌時,我只能選擇允許或拒絕,而不是任何特定的權限。編輯:nevermind,我看到在我的appname下的下拉列表中有一個按鈕。 – twan

+0

您在生成用戶令牌時也獲得了manage_pages。此外只需選擇publish_pages。 – luschn

+0

是的,甚至有一個單獨的函數來授權publish_pages – luschn