dongtan2603 2016-11-24 16:00
浏览 60

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

I keep getting the following error:

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

I have read other Stackoverflow posts and they do not help. The path to my FB SDK is correct. I am using version 5.0 of the FB SDK (the latest)

I have included both Facebook.php and autoload.php and also tried each require_once for each file separately, same error. No other errors are provided.

I am not sure what I am doing wrong. Please help

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 随机森林与房贷信用风险模型
    • ¥50 buildozer打包kivy app失败
    • ¥30 在vs2022里运行python代码
    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备