Reputation: 73
I have implemented login system that return access token on my application end using facbook graph api. But while I tried to user information using following scripts I am getting error.
My scripts:
require_once __DIR__ . '/facebook-php-sdk-v4-5.0-dev/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'appId' => 'appid',
'secret' => 'secret',
'default_graph_version' => 'v2.2'
]);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me?fields=id,name', 'some access token');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$user = $response->getGraphUser();
echo 'Name: ' . $user['name'];
Error experienced:
Fatal error: Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Required "app_id" key not supplied in config and could not find fallback environment variable "FACEBOOK_APP_ID"' in B:\xampp\htdocs\SocialAPI\facebook-php-sdk-v4-5.0- dev\src\Facebook\Facebook.php:133 Stack trace: #0 B:\xampp\htdocs\SocialAPI\loginSuccess.php(22): Facebook\Facebook->__construct(Array) #1 {main} thrown in B:\xampp\htdocs\SocialAPI\facebook-php- sdk-v4-5.0-dev\src\Facebook\Facebook.php on line 133
Please let me know i can I resolve this error.
Upvotes: 1
Views: 3831
Reputation: 726
It's seems that your Facbook.php file expecting app_id instead of appId
In order to resolve at first open your following file:
B:\xampp\htdocs\SocialAPI\facebook-php-sdk-v4-5.0- dev\src\Facebook\Facebook.php
Then look for appId whether exist or not. If not appId not found then update your config as following:
$fb = new Facebook\Facebook([
'app_id' => 'appid',
'secret' => 'secret',
'default_graph_version' => 'v2.2'
]);
If your issue doesn't resolve please let know.
Upvotes: 4