I am using facebook graph api in laravel 5.1.I have installed it usnig composer command
composer require facebook/php-sdk-v4
the facebook graph api has been installed but when i create the facebook api object in laravel then it's give me this error
Class 'App\Http\Controllers\Userapp\Facebook\Facebook' not found
it is in this line
$fb = new Facebook\Facebook([
here is my Controller file
<?php namespace App\Http\Controllers\Userapp;
require_once( base_path('vendor/facebook/php-sdk-v4/src/Facebook/autoload.php') );
// Facebook Requires
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\Entities\AccessToken;
use Facebook\HttpClients\FacebookHttpable;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookCurl;
and the function of the controller
public function index()
{
// init app with app id and secret
$fb = new Facebook\Facebook([
'app_id' => 'xxxxxxxxxxxxxxx',
'app_secret' => 'xxxxxxxxxxxxxxxxx',
'default_graph_version' => 'v2.5',
//'default_access_token' => '{access-token}', // optional
]);
try {
// Get the Facebook\GraphNodes\GraphUser object for the current user.
// If you provided a 'default_access_token', the '{access-token}' is optional.
$response = $fb->get('/me', '{access-token}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$me = $response->getGraphUser();
echo 'Logged in as ' . $me->getName();
}
kindly help me solving this problem. i will really appreciate that Thanks