我正在開發一個需要Facebook集成的PHP項目。所以在我做代碼之前,我正在使用Facebook Graph API瀏覽器工具(https://developers.facebook.com/tools/explorer)測試它。我現在正在做的是。如何使用CURL在Facebook上發佈帖子,而不使用PHP中的SDK
第一步驟
Get the user access_token by using the button at the top left.
第二步驟
Make a GET request to "me/accounts" to get the page token and page id.
第三步驟
Make a POST request to "{page_id}/feed" with the fields message={message} and access_token={page_token}
它工作完美,張貼在我的Facebook粉絲頁。但是,當我嘗試用這樣的PHP代碼代替「第三步」時
$data['message'] = "my message";
$data['access_token'] = $page_access_token; //page token from 2nd step
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://graph.facebook.com/{page_id}/feed');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
$resp = curl_exec($ch);
curl_close($ch);
$data_resp = json_decode($resp);
print_r($data_resp);
它向我顯示這個錯誤。
stdClass Object ([error] => stdClass Object ([message] => (#200) Permissions error [type] => OAuthException [code] => 200))
我設置的manage_pages,publish_pages,publish_actions權限
調試你的'access_token'並檢查它是否獲得了所需的權限。 https://developers.facebook.com/tools/debug/ – Criesto