2017-04-16 119 views
-1
<?php 
    require_once("facebook.php"); // set the right path 

    $config = array(); 
    $config['appId'] = ''; 
    $config['secret'] = ''; 
    $config['fileUpload'] = false; // optional 
    $fb = new Facebook($config); 

    $params = array(
     // this is the main access token (facebook profile) 
     "access_token" => "EAAHHbZBnyVlsBAFx1X4LVrxouuTYZB5IDsd7PI2FQica9tqNNvzInPKP9KHPQKJPfxITGy6ZCuSjOFPChrD4f5damVXSeC2O6w7BZATUNp7s8nTZBVn8ZBdyKuVpbQeTU4mZBVrUJ92IUwP7Ubli9JJuUrtqZAwOe1ZCv751ZBNOoO80fXyATn0ztaU8OQZD", 
     "message" => "", 
     "name" => "", 
     "caption" => "", 
     "description" => "" 
    ); 

    try { 
     $ret = $fb->api('/me/feed', 'POST', $params); 
     echo 'Successfully posted to Facebook Personal Profile'; 
    } catch(Exception $e) { 
     echo $e->getMessage(); 
    } 
    ?> 

我創建了一個服務器端的PHP應用程序,職位狀態自動對我的FB但是當我運行的應用程序,它顯示了一個錯誤信息:錯誤驗證訪問令牌:會話已過期

Error validating access token: Session has expired 
+0

刪除代碼段和相關的應用程序,你給我們你的代幣:< –

+0

也許這個職位可能對你有用:http://stackoverflow.com/questions/13953265/facebook-non-expiring-access-token?rq = 1 – Tjoene

+0

[一般](https://developers.facebook.com/docs/facebook-login/access-tokens)您的訪問令牌不是靜態的,您必須瞭解oauth或至少以正確的方式使用sdk 。 –

回答

0
<?php 
// require Facebook PHP SDK 
// see: https://developers.facebook.com/docs/php/gettingstarted/ 
require_once("facebook.php"); 

// initialize Facebook class using your own Facebook App credentials 
// see: https://developers.facebook.com/docs/php/gettingstarted/#install 
$config = array(); 
$config['appId'] = ''; 
$config['secret'] = ''; 
$config['fileUpload'] = false; // optional 

$fb = new Facebook($config); 

// define your POST parameters (replace with your own values) 
$params = array(
    "access_token" => "EAAHHbZBnyVlsBAFx1X4LVrxouuTYZB5IDsd7PI2FQica9tqNNvzInPKP9KHPQKJPfxITGy6ZCuSjOFPChrD4f5damVXSeC2O6w7BZATUNp7s8nTZBVn8ZBdyKuVpbQeTU4mZBVrUJ92IUwP7Ubli9JJuUrtqZAwOe1ZCv751ZBNOoO80fXyATn0ztaU8OQZD", // see: https://developers.facebook.com/docs/facebook-login/access-tokens/ 

    "message" => "", 
    "link" => "", 
    "picture" => "", 
    "name" => "How to Auto Post on Facebook with PHP", 
    "caption" => "", 
    "description" => "Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation." 
); 

// post to Facebook 
// see: https://developers.facebook.com/docs/reference/php/facebook-api/ 
try { 
    $ret = $fb->api('/YOUR_FACEBOOK_ID/feed', 'POST', $params); 
    echo 'Successfully posted to Facebook'; 
} catch(Exception $e) { 
    echo $e->getMessage(); 
} 
?> 

試試這個.... http://www.pontikis.net/blog/auto_post_on_facebook_with_php 在代碼中添加您的AppID,密鑰和您的Facebook ID!

相關問題