Facebook错误:“致命错误:未找到类'Facebook'

时间:2016-11-24 16:00:03

标签: php facebook

我一直收到以下错误:

Fatal error: Class 'Facebook' not found in /path/to/a/script/fbpostapp.php on line 14

我已阅读其他Stackoverflow帖子但他们没有帮助。我的FB SDK的路径是正确的。我使用的是FB SDK 5.0版(最新版)

我已经包含了Facebook.php和autoload.php,并且还分别为每个文件尝试了每个require_once,同样的错误。没有提供其他错误。

我不确定我做错了什么。请帮忙

<?php
// require Facebook PHP SDK
// see: https://developers.facebook.com/docs/php/gettingstarted/
// require_once("/YOUR_PATH_TO/facebook_php_sdk/facebook.php");
require_once 'php-graph-sdk-5.0.0/src/Facebook/Facebook.php';
require_once 'php-graph-sdk-5.0.0/src/Facebook/autoload.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" => "YOUR_ACCESS_TOKEN", // see:     https://developers.facebook.com/docs/facebook-login/access-tokens/
  "message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook",
  "link" => "http://www.pontikis.net/blog/auto_post_on_facebook_with_php",
  "picture" => "http://i.imgur.com/lHkOsiH.png",
  "name" => "How to Auto Post on Facebook with PHP",
  "caption" => "www.pontikis.net",
  "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();
}
?>

0 个答案:

没有答案