php 'Class 'Facebook\Facebook' not found" Facebook SDK 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32366714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'Class 'Facebook\Facebook' not found" Facebook SDK error
提问by Wocugon
Well I am new to facebook sdk. I have being following the guideline and performing the steps as written.. but I am getting this error and I dont know why?
好吧,我是 facebook sdk 的新手。我一直在遵循指南并按照所写的步骤执行..但我收到此错误,我不知道为什么?
Fatal error: Class 'Facebook\Facebook' not found in C:\wamp\www\index.php on line 134
The error line code is:
错误行代码是:
<?php
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.2',
]);
?>
This is not something I have made up, this is exactly the same code mentioned in facebook guideline! What should I do?
这不是我编造的,这与 facebook 指南中提到的代码完全相同!我该怎么办?
回答by q.Then
You need to include the autoloader
first to get access to the service methods and classes (as said in the PHP SDK Documentation for Facebook
API. You are trying to use a namespaced class Facebook\Facebook
, to use its methods, but you don't have the class in the PHP file.
您需要包含第autoloader
一个来访问服务方法和类(如Facebook
API的 PHP SDK 文档中所述。您正在尝试使用命名空间类Facebook\Facebook
来使用其方法,但您在PHP 文件。
require_once 'src/Facebook/autoload.php';
//Create the Facebook service
$fb = new Facebook\Facebook ([
'app_id' => '-----------------',
'app_secret' => '--------------------',
'default_graph_version' => 'v2.4'
]);
Somewhere in your directory (if you installed the Facebook PHP SDK) correctly, you will find the autoload.php
file which automatically requires
.php files that you need to use the services and methods.
在您的目录中的某处(如果您安装了 Facebook PHP SDK)正确,您会autoload.php
自动找到requires
使用服务和方法所需的 .php 文件。
回答by Yifan Fan
I think you need to first import that php class into your current file
我认为您需要先将该 php 类导入到您当前的文件中
Put this line at the top
将此行放在顶部
use Facebook\Facebook;
回答by AppEmmanuel
Download the zip file from here : https://github.com/facebook/php-graph-sdk/archive/5.4.zip
从这里下载 zip 文件:https: //github.com/facebook/php-graph-sdk/archive/5.4.zip
Steps :
脚步 :
Unzip the content (by either just double clicking on the zipped file or use any available unzipping software to unzip or decompress the downloaded file)
Navigate to the "src" folder.
Copy or cut the "src" folder and paste right within the folder from which you have your php files.
make sure you have created "includes.php" file within your php project workspace ie. the folder in which your web page is sitting. And add this line to your "includes.php" file :
require_once 'src/Facebook/autoload.php';
Now in your php file(s) that has to do with facebook you can then add :
require_once("includes.php");
Now save your file and go into your browser and refresh.
解压缩内容(只需双击压缩文件或使用任何可用的解压缩软件来解压缩或解压缩下载的文件)
导航到“src”文件夹。
复制或剪切“src”文件夹并直接粘贴到您的 php 文件所在的文件夹中。
确保您已在 php 项目工作区中创建了“includes.php”文件,即。您的网页所在的文件夹。并将这一行添加到您的“includes.php”文件中:
require_once 'src/Facebook/autoload.php';
现在,在与 facebook 相关的 php 文件中,您可以添加:
require_once("includes.php");
现在保存您的文件并进入浏览器并刷新。
//Do remember to keep your work organised by now referencing all files that may be needed in your project via "includes.php". This may vary for some developers, depending on how and what you are working on.
//请记住通过“includes.php”引用项目中可能需要的所有文件来保持您的工作井井有条。对于某些开发人员,这可能会有所不同,具体取决于您的工作方式和工作内容。