2015-04-19 60 views

回答

0

如果沒有授權,您無法在Facebook上發佈任何內容。如果你想發佈「作爲頁面」,你需要授權頁面管理員使用「publish_pages」權限並使用頁面標記。您無法獲得未經授權的用戶或頁面標記,當然您也不能自動執行授權過程。檢查出的文檔的詳細信息:https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed#publish

您還需要了解訪問令牌:

0

其實都是我特別希望有永久頁面訪問令牌,所以我可以永久自動發佈,無需每次發佈時都要求用戶驗證。

請按照下列步驟來獲得它:Permanent Access Token

然後使用自動郵編:

session_start(); 
define('FACEBOOK_SDK_V4_SRC_DIR', 'facebook-php-sdk-v4-4.0-dev/src/Facebook/'); 
require __DIR__ . '/facebook-php-sdk-v4-4.0-dev/autoload.php'; 

use Facebook\FacebookSession; 
use Facebook\FacebookRequest; 
use Facebook\GraphUser; 
use Facebook\FacebookRequestException; 
use Facebook\FacebookRedirectLoginHelper; 

// Facebook App 
$api_key = 'xxxxxxxxxxxxxxxx'; //App ID 
$api_secret = 'xxxxxxxxxxxxxxxx'; //App Secret 
$page_id = 'xxxxxxxxxxxxxxxx'; //Page ID 
$page_token = 'from the steps in the url'; 
$fb_post = array(
       'message'=> 'test message', 
       'name'=> '', 
       'link'=> 'http://www.example.com/', 
       'picture'=> 'http://www.example.com/image.jpg', 
       'caption'=> '', 
    ); 

// start a session for this App 
FacebookSession::setDefaultApplication($api_key, $api_secret); 

try { 
    $session = new FacebookSession($page_token); 
} catch(FacebookRequestException $e) { 
    die(" Error : " . $e->getMessage()); 
} catch(\Exception $e) { 
    die(" Error : " . $e->getMessage()); 
} 

try { 
// Auto posting 
    $page_post = (new FacebookRequest($session, 'POST', '/'. $page_id .'/feed', $fb_post))->execute()->getGraphObject()->asArray(); 
// return post_id, optional 
    print_r($page_post); 
} catch (FacebookRequestException $e) { 
    // The Graph API returned an error 
    echo '<b style="color:blue;">'.$e->getMessage().'</b>'; 
} catch (\Exception $e) { 
    // Some other error occurred 
    echo '<b style="color:red;">'.$e->getMessage().'</b>'; 
} 
相關問題