简体   繁体   中英

Error using Facebook Log in with PHP sdk 4.0

I am trying to code Facebook log with php sdk 4.0 in to my website I have setup all the settings on my facebook app and im sure all the details are correct in my files. so my users can log in using they're Facebook account but I have run into a problem. I go to my website and click the log in link and it goes back to my website but this time it has a ?code= with lots of params and a error is displayed

And just to say the domain is a local domain I edited my hosts file and added

127.0.0.1 ashleyisawsome.com

And the error i have when i click login is

Fatal error: Class 'Facebook\FacebookCurlHttpClient' not found in C:\xampp\htdocs\fb\Facebook\FacebookRequest.php on line 154

I looked in FacebookRequest.php and all i found was the line below

return static::$httpClientHandler ?: static::$httpClientHandler = new FacebookCurlHttpClient();

So i am guessing the error is with the

new FacebookCurlHttpClient();

Can anyone help me out with this please? Here is my main index.php file

<?php

 session_start();
 include 'Facebook/FacebookSession.php';
 include '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/FacebookAuthorizationException.php' );
 require_once( 'Facebook/GraphObject.php' );
 require_once( 'Facebook/GraphUser.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;
 use Facebook\GraphUser;
 FacebookSession::setDefaultApplication('',     '');
 $helper = new FacebookRedirectLoginHelper('http://ashleyisawsome.com/fb/index.php');
 $session = $helper->getSessionFromRedirect();
 if($session != NULL){
 echo "Logged In !<br>"; 
 $request = new FacebookRequest($session, 'GET', '/me');
 $response = $request->execute();
 $graph = $response->getGraphObject(GraphUser::className());
 echo $graph->getName();
 }
 else{
 echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
 }
 ?>

EDIT : I have fixed this but it know says this?

Fatal error: Interface 'Facebook\FacebookHttpable' not found in C:\xampp\htdocs\fb\Facebook\FacebookCurlHttpClient.php on line 31

You must include / call the FacebookHttpable class / namespace -BEFORE- the FacebookCurlHttpClient class / namespace

//all other requires here
require_once( 'FacebookHttpable.php' );
require_once( 'FacebookCurlHttpClient.php' );

//all other namespaces here
use Facebook\FacebookHttpable;
use Facebook\FacebookCurlHttpClient;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM