验证访问令牌时出错:会话已过期

时间:2017-04-16 07:36:09

标签: php facebook token

32

我创建了一个服务器端PHP应用程序,它在我的FB页面上自动发布状态但是当我运行应用程序时,它显示一条错误消息:

<?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();
    }
    ?>

1 个答案:

答案 0 :(得分: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