0

Usually this works but I don't know why it isn't. It's giving me the following error: Fatal error: Class 'FacebookSession' not found in C:\xampp\htdocs\app\index.php on line 9

In my index.php:

 <?php
  include 'include.php';
  --- rest of my code
  ?>

In my include.php:

 <?php
  require_once( 'Facebook/HttpClients/FacebookHttpable.php' );
  require_once( 'Facebook/HttpClients/FacebookCurl.php' );
  require_once( 'Facebook/HttpClients/FacebookCurlHttpClient.php' );

  require_once( 'Facebook/Entities/AccessToken.php' );
  require_once( 'Facebook/Entities/SignedRequest.php' );

  require_once( 'Facebook/FacebookSession.php' );
  require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
  require_once( 'Facebook/FacebookRequest.php' );
  require_once( 'Facebook/FacebookResponse.php' );
  require_once( 'Facebook/FacebookSDKException.php' );
  require_once( 'Facebook/FacebookRequestException.php' );
  require_once( 'Facebook/FacebookServerException.php' );
  require_once( 'Facebook/FacebookOtherException.php' );
  require_once( 'Facebook/FacebookAuthorizationException.php' );
  require_once( 'Facebook/GraphObject.php' );
  require_once( 'Facebook/GraphSessionInfo.php' );

  use Facebook\HttpClients\FacebookHttpable;
  use Facebook\HttpClients\FacebookCurl; 
  use Facebook\HttpClients\FacebookCurlHttpClient;

  use Facebook\Entities\AccessToken;
  use Facebook\Entities\SignedRequest;

  use Facebook\FacebookSession;
  use Facebook\FacebookRedirectLoginHelper;
  use Facebook\FacebookRequest;
  use Facebook\FacebookResponse;
  use Facebook\FacebookSDKException;
  use Facebook\FacebookRequestException;
  use Facebook\FacebookServerException;
  use Facebook\FacebookOtherException;
  use Facebook\FacebookAuthorizationException;
  use Facebook\GraphObject;
  use Facebook\GraphSessionInfo;
  ?>

I must be missing something really silly. Because this should work?

fondillusions
  • 189
  • 1
  • 2
  • 13
  • possible duplicate of [Error: Class 'Facebook\FacebookSession' not found with the facebook PHP SDK](http://stackoverflow.com/questions/23569934/error-class-facebook-facebooksession-not-found-with-the-facebook-php-sdk) – Rajesh Ujade Sep 09 '14 at 04:59
  • Don't need to use require_once.For this you need to use namespaces.For detail answer check:http://stackoverflow.com/questions/23413854/facebook-sdk-v4-for-php-minimal-example/25737047#25737047 – Rajesh Ujade Sep 09 '14 at 05:20

1 Answers1

0
UPDATE

Trouble Shoot Your Code

foo foo foo
echo '1';
foo foo foo 
echo '2';
foo foo foo
echo '3';

This is a file pathing issue.

This is how my file structure works,

RootDir/

actions/fbhandshakes
facebook/ //this is the api
includes header.php
index.php

in actions/fbhandshakes

// include required classes from Facebook SDK
require_once( 'facebook/src/Facebook/FacebookHttpable.php' );
require_once( 'facebook/src/Facebook/FacebookCurl.php' );
require_once( 'facebook/src/Facebook/FacebookCurlHttpClient.php' );
require_once( 'facebook/src/Facebook/FacebookSession.php' );
require_once( 'facebook/src/Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'facebook/src/Facebook/FacebookRequest.php' );
require_once( 'facebook/src/Facebook/FacebookResponse.php' );
require_once( 'facebook/src/Facebook/FacebookSDKException.php' );
require_once( 'facebook/src/Facebook/FacebookRequestException.php' );
require_once( 'facebook/src/Facebook/FacebookOtherException.php' );
require_once( 'facebook/src/Facebook/FacebookAuthorizationException.php' );
require_once( 'facebook/src/Facebook/GraphObject.php' );
require_once( 'facebook/src/Facebook/GraphSessionInfo.php' );

// Called class with namespace
use Facebook\FacebookHttpable;
use Facebook\FacebookCurl;
use Facebook\FacebookCurlHttpClient;
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookOtherException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphSessionInfo;
// This is the rest of the my facebook call from here down ...

In header.php I include the whole facebook call

require_once( 'actions/fbHandshake.php' ); 

Then I add header to my index.php file.

require_once( 'includes/header.php' );
wuno
  • 9,547
  • 19
  • 96
  • 180
  • That's not the problem. It works when I include all the files in my index.php.... I am just struggling to create an external file to include it all. Hoping to make it easier for me to make separate php files instead of having to include all those files every time :S sorry if my question wasn't very clear. – fondillusions Jul 31 '14 at 14:45
  • @fondillusions Oh, sorry about that. If you remove the line with the error, does the error move to the next line down? For example, remove ` require_once( 'Facebook/HttpClients/FacebookHttpable.php' );` Does the error now show here, ` require_once( 'Facebook/FacebookRedirectLoginHelper.php' );` ? – wuno Jul 31 '14 at 14:49
  • When I remove 'require_once( 'Facebook/HttpClients/FacebookHttpable.php' I get this error Fatal error: Interface 'Facebook\HttpClients\FacebookHttpable' not found in C:\xampp\htdocs\app\Facebook\HttpClients\FacebookCurlHttpClient.php on line 33 – fondillusions Jul 31 '14 at 14:59
  • Not sure why it doesn't work. In theory it should, because it works when I include them all in the index.php. When including an external php, it should essentially just replace all the content in that file into my code. Hmm, I could just leave it in one file.. – fondillusions Jul 31 '14 at 15:23
  • Its hard for me to say from here. Its obviously a file path issue. with the include. I do the same thing on my server like this, ill edit my answer with my file structure. – wuno Jul 31 '14 at 15:26
  • Both files are in the same directory. And the path to the files worked when they were in index.php so surely the path shouldn't change? I'm confused! But okay, thank you! – fondillusions Jul 31 '14 at 15:34
  • Something I would do at this point would be start at the first line of the code and add echo 'hey this is #1'; under the next line add echo 'hey this is #2'; and so on... do this and run the file to see where it stops. once you see the line adjust the file path to see if it changes. Its pretty obvious it a file path. I feel over dedicated now so we must achieve victory! lol – wuno Jul 31 '14 at 15:36
  • Haha thank you for the dedication :). Should I do this in index.php then? – fondillusions Aug 01 '14 at 10:55
  • I updated with example. No, go in to your include.php file and echo something that can show us where the code runs to before it breaks. Then we can start figuring out where the error is. Its going to be at a file path at one of those require statements. But I want to rule out that it is not anything else. Also I want to see if it finds some files but cant find other ones. – wuno Aug 01 '14 at 14:34
  • It runs... it echoes everything in every line :S but still getting the error Fatal error: Class 'FacebookSession' not found in C:\xampp\htdocs\app\index.php on line 10. – fondillusions Aug 01 '14 at 14:39
  • my index.php? urghh I don't understand, it echoes, but it doesn't get the classes? Does yours work? – fondillusions Aug 01 '14 at 14:47
  • lol yes mine works fine. im trying to figure out if its your namespace thats not working or your file paths in your require statements. remove the `use 'blablah' statements`. only leaving the require. – wuno Aug 01 '14 at 14:51
  • My path is different to yours though. index.php include.php facebook/ <-- within facebook folder I have all the sdk php files. – fondillusions Aug 01 '14 at 14:51
  • follow each path in to your facebook folder and make sure your paths are correct. Also if your facebook folder is lowercase f change it to uppercase F cause your showing me two different ways. – wuno Aug 01 '14 at 14:53
  • :'(! It can't be the path because it works when I have it in my index.php!?? It's uppercase F. The paths are right. I took the use statements out. I get the same error - no difference. – fondillusions Aug 01 '14 at 14:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/58501/discussion-between-fondillusions-and-ndiaz). – fondillusions Aug 01 '14 at 14:58