Reputation: 145
I am very new to PHP and I am trying to write a simple program based on this tutorial, https://benmarshall.me/facebook-php-sdk/, to get my profile name off of Facebook. But I keep getting an error. the problem appears to be with my path to autoload.php but I think I have the right path. But maybe not.
Practice.php
<?php
require_once __DIR__ . 'Facebook/vendor/autoload.php'; // change path as needed
$fb = new \Facebook\Facebook([
'app_id' => '{}',
'app_secret' => '{}',
'default_graph_version' => 'v3.3',
//'default_access_token' => '{access-token}', // optional
]);
// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
// $helper = $fb->getRedirectLoginHelper();
// $helper = $fb->getJavaScriptHelper();
// $helper = $fb->getCanvasHelper();
// $helper = $fb->getPageTabHelper();
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();
Error Message
[north@oreo ~/Facebook]$ php Practice.php
Warning: require_once(/usr/home/north/FacebookFacebook/vendor/autoload.php): failed to open stream: No such file or directory in /usr/home/north/Facebook/Practice.php on line 2
Fatal error: require_once(): Failed opening required '/usr/home/north/FacebookFacebook/vendor/autoload.php' (include_path='.:/usr/local/share/pear') in /usr/home/north/Facebook/Practice.php on line 2
[north@oreo ~/Facebook]$
Upvotes: 1
Views: 186
Reputation: 145
Like the comments said all I needed to do to fix it was change Facebook/vendor/autoload.php
to /vendor/autoload.php
Upvotes: 1