致命错误:找不到类"FacebookRequest" [英] Fatal error: Class 'FacebookRequest' not found

查看:95
本文介绍了致命错误:找不到类"FacebookRequest"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定我所做的一切都正确,而且我知道我的服务器设置和facebook设置都正确,因为当我将zend与自动加载器一起使用时,这可以正常工作,但是现在我不明白,坦白地说,我不了解自定义自动加载器和手册超级清晰,所以这可能是我的问题.我有的问题是,当我声明new FacebookRequest php时抛出一个错误,提示Fatal error: Class 'FacebookRequest' not found,但是正在使用包含的文件. sdk不会抛出其他错误.

I am certain I'm doing everything right and i know my server settings and facebook settings are right because this worked when i was using zend with an autoloader, however now im not and frankly i dont understand custom autoloaders and the manual wasnt super clear, so that may be my issue. the problem im having is when i declare new FacebookRequest php throws an error saying Fatal error: Class 'FacebookRequest' not found however the file is included is is being used. there are no other errors that the sdk is throwing.

我的config.php

my config.php

require_once('facebook/FacebookSession.php');
require_once('facebook/FacebookRedirectLoginHelper.php');
require_once('facebook/FacebookHttpable.php');
require_once('facebook/FacebookCurl.php');
require_once('facebook/FacebookCurlHttpClient.php');
require_once('facebook/FacebookRequest.php');
require_once('facebook/FacebookResponse.php');
require_once('facebook/FacebookSDKException.php');
require_once('facebook/FacebookRequestException.php');
require_once('facebook/FacebookAuthorizationException.php');
require_once('facebook/GraphObject.php');

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;

//start session if its not started already
if(session_id() == '') {
session_start();
}

// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('APPID','SECRET');
$FBHelper = new FacebookRedirectLoginHelper('http://website.org/registration.php', $appId = $FBAppID, $appSecret = $FBAppSecret);

我的"website.org/registration.php"

my "website.org/registration.php"

//if were redirecting back from FB auth
try {
    $session = $FBHelper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
    echo $ex;
    die("<br><br>Facebook made an error");
} catch(\Exception $ex) {
    echo $ex;
    die("<br><br>It appears I messed up");
}

//check if were logged in or if we need to further our registration process
if (isset($session)) {
    //try to grab the user data to send to our database
    try {
        $user_profile = (new FacebookRequest(//heres the error
            $session, 'GET', '/me'
        ))->execute()->getGraphObject(GraphUser::className());          
    } catch(FacebookRequestException $e) {
        //if we're here then we failed getting the users data
        echo "Exception occured, code: " . $e->getCode();
        echo " with message: " . $e->getMessage();
    }   

推荐答案

它是在Facebook名称空间中定义的.

It's defined in a Facebook namespace.

这意味着您必须在每个文件中添加

It means that in every file you must add

use Facebook\FacebookRequest;

以便php知道此类.

或者您也可以使用完全限定的名称:new use \Facebook\FacebookRequest(...)

Or you could use a fully qualified name instead: new use \Facebook\FacebookRequest(...)

这篇关于致命错误:找不到类"FacebookRequest"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆