1

PHP Fatal error: Class 'Facebook' not found in /mnt/releases/server/asrivastava/first-task/390f5294f2b74ffbbe729e1ce9773c39573973b8/public/subscribe.php on line 36

<?php
try{
    include_once "./php-sdk/src/facebook.php";
}
catch(Exception $o){
    echo '<pre>';
    print_r($o);
    echo '</pre>';
}

error_log("Subscribe.php");
error_log("included facebook classes");
define ("FB_APPID" ,"APPID") ;
define ("FB_SECRET", "KEY");
define ("VERIFY_TOKEN" ,"myFirstFB");

$access_token = "MyAccessToken";
$user = array(
        "first_name",
        "last_name"
    ) ;
$param = array('access_token' => $access_token,
        'object' => 'user',
        'fields' => 'name, feed, likes',
     //   'callback_url' => 'http://apps.facebook.com./handleCallBack.php',
        'callback_url' => 'SomeUrl',
        'verify_token' => VERIFY_TOKEN
);
$config = array ('appId' => FB_APPID, 'secret' => FB_SECRET);
    error_log("Created FB object");
$fb = new Facebook($config);
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
error_log("made curl call");
try {

$subs = $fb->api('/'.APP_ID.'/subscriptions', 'POST', $param);
var_dump($subs);
} catch (FacebookApiException $e) {
    echo $e->getCode()." ".$e->getType()." ".$e->getMessage()." ".$e->getFile()." ".$e-                  >getLine()."\n";
}


?>

Now whenever I hit this URL I get the error metioned above. kindly suggest me a way through it please.

Error Log :

[Mon Apr 16 06:51:02 2012] [error] [client 172.20.2.144] Subscribe.php [Mon Apr 16 06:51:02 2012] [error] [client 172.20.2.144] included facebook classes [Mon Apr 16 06:51:02 2012] [error] [client 172.20.2.144] Created FB object [Mon Apr 16 06:51:02 2012] [error] [client 172.20.2.144] PHP Fatal error: Class 'Facebook' not found in /mnt/releases/server/asrivastava/first-task/390f5294f2b74ffbbe729e1ce9773c39573973b8/public/subscribe.php on line 36 [Mon Apr 16 06:51:02 2012] [error] [client 172.20.2.144] PHP Stack trace: [Mon Apr 16 06:51:02 2012] [error] [client 172.20.2.144] PHP 1. {main}() /mnt/releases/server/asrivastava/first-task/390f5294f2b74ffbbe729e1ce9773c39573973b8/public/subscribe.php:0 [Mon Apr 16 06:51:06 2012] [error] [client 172.20.2.144] File does not exist: /var/www/server_releases/asrivastava/first-task/flash,

3
  • What does this file look like: ./php-sdk/src/facebook.php ? The problem you are having is that your script can not find the Facebook class which is most likely supposed to be defined in this file. Also try removing the try/catch around the include, as this file is necessary to continue the execution at all. Commented Apr 16, 2012 at 11:12
  • 1
    Replace the try/catch-struct in the beginning with only this line: require_once('./php-sdk/src/facebook.php'); Commented Apr 16, 2012 at 12:24
  • @fulhack : developers.facebook.com/docs/reference/php and I tried, without try/catch block as well but its yet not being included Commented Apr 17, 2012 at 13:04

2 Answers 2

4

I had same problem. Here's what I did wrong that you might have done:

When I went to this page: https://github.com/facebook/facebook-php-sdk/tree/master/src to download facebook.php, base_facebook.php, etc.

I right-clicked and did "Save Link As" not realizing that I wasn't saving what I thought I was saving.

SOLUTION: click those links and THEN copy and paste the code into facebook.php, etc.

Sign up to request clarification or add additional context in comments.

1 Comment

or take the raw link github offers - if you can't clone with git.
0

The problem is most likely that you're using a slightly incorrect path in the include at the top of the file.

First, replace include_once with require_once - this will give you an error if it can't find the file, rather than carrying on regardless.

Assuming that is the error, check carefully where the file to be included is in relation to your subscribe.php

"./php-sdk/src/facebook.php" means "start at the current directory (".") and look in a sub-directory called php-sdk/src for facebook.php". So in your case, the full path it's trying to load is "/mnt/releases/server/asrivastava/first-task/390f5294f2b74ffbbe729e1ce9773c39573973b8/public/php-sdk/src/facebook.php"

Maybe your "php-sdk" directory is actually one level up? In that case you want your path to begin ".." not "." ("../php-sdk/src/facebook.php" would mean "/mnt/releases/server/asrivastava/first-task/390f5294f2b74ffbbe729e1ce9773c39573973b8/php-sdk/src/facebook.php")

Also, since this appears to be Linux/Unix server, the paths will all be case sensitive, so if your file is called "FaceBook.php", that is not the same as "facebook.php".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.