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.
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.
Related
My function to list add_group_account id of a particular user ends up by receiving the following error.
Message: Unknown path components: /adaccountgroups
I'm following this guideline Facebook API documentation
public function tp()
{
$fb = new Facebook([
'app_id' => "621201298943758",
'app_secret' => "f0aa4ae743ef.................",
'default_graph_version' => 'v2.5',
'default_access_token' => "EAAI0ZBrLB7w4BAIUyoGjSB50ZBsXbPxYfCjk6WxPQIa.................................",
]);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/me/adaccountgroups',
'EAAI0ZBrLB7w4BAIUyoGjSB50ZBs.....................'
);
} 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;
}
$graphNode = $response->getGraphNode();
}
As I have discovered there is no endpoint or function by the name "adaccountgroups"available even though it was mentioned in their own documentation.
To get the add account ID corresponding to a particular user account it has to be called in following pattern
curl
https://graph.facebook.com/v13.0/me/adaccounts?access_token=EAAI0ZBrLB7w...............
SDK
$response = $fb->get(
'/me/adaccounts',
'{token.....}'
);
Very new to PHP and downloaded Facebook-PHP-SDK and I am trying to run a simple code I found online but I keep getting an error. I have done lots of research on the problem, looked at similar questions on here and so for but have not been able to find anything that helps. It looks like I still need to authorize the app I created in Facebook Developers, but I cannot figure out how to do that.
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => '{}',
'app_secret' => '{}',
'persistent_data_handler' => 'memory',
'default_graph_version' => 'v3.3',
]);
$helper = $fb->getCanvasHelper();
try {
$accessToken = $helper->getAccessToken();
} 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;
}
if (! isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
}
// Logged in
echo '<h3>Signed Request</h3>';
var_dump($helper->getSignedRequest());
echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());
Error Message
No OAuth data could be obtained from the signed request. User has not authorized your app yet.
You are not supplying the SDK with the required app_id and app_secret so it can't do anything. That's why it gives you an OAUTH error. (fb-docs)
$fb = new Facebook\Facebook([
'app_id' => '{}', // Here
'app_secret' => '{}', // Here
'persistent_data_handler' => 'memory',
'default_graph_version' => 'v3.3',
]);
You need to get that data from your facebook app configuration dashboard. And plug into this object.
example:
$app_id = "1234";
$app_secret = "foobar";
$fb = new Facebook\Facebook([
'app_id' => '{$app_id}',
'app_secret' => '{$app_secret}',
'default_graph_version' => 'v3.2',
]);
Apps are all registered and managed at https://developers.facebook.com/ . Have you checked your settings there?
Very new to PHP and I trying to write a program using Facebook PHP SDK and right now I am trying to get the following tutorial to work, https://developers.facebook.com/docs/php/howto/example_retrieve_user_profile, but I keep getting an error. I think it might have to do with the access token. I do not know if I am suppose to put something else there or not. And if I am how do I get my access token? Right now I just left it the way it was in the tutorial. But the error is saying something is wrong with line 2, so maybe the problem is there. Not quite sure. So any help would be greatly appreciated!
Error Message
[north#oreo ~/Facebook]$ php Practice_2.php
Fatal error: Uncaught Error: Class 'Facebook\Facebook' not found in /usr/home/north/Facebook/Practice_2.php:2
Stack trace:
#0 {main}
thrown in /usr/home/north/Facebook/Practice_2.php on line 2
Practice_2.php
<?php
$fb = new Facebook\Facebook([
'app_id' => '{}',
'app_secret' => '{}',
'default_graph_version' => 'v3.3',
]);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me?fields=id,name', '{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'];
// OR
// echo 'Name: ' . $user->getName();
From the docs
When someone connects with an app using Facebook Login and approves the request for permissions, the app obtains an access token that provides temporary, secure access to Facebook APIs.
I'm trying to get a list of the users friends with php but it keeps throwing an exception the code is the same from Facebook for developers docs
https://developers.facebook.com/docs/graph-api/reference/v3.0/user/friends
here is my code
$fb = new \Facebook\Facebook([
'app_id' => APP_ID,
'app_secret' => APP_SECRET,
'default_graph_version' => DEFAULT_GRAPH_VERSION,
//'access_token' => '{'.$fbToken.'}', // optional
]);
try {
$response = $fb->get('/friends', $fbToken);
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
And here is the stacktrace of the error
[03-Jul-2018 07:29:33 UTC] PHP Fatal error: Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Unable to convert response from Graph to a GraphNode because the response looks like a GraphEdge. Try using GraphNodeFactory::makeGraphEdge() instead.' in /facebook/Facebook/GraphNodes/GraphNodeFactory.php:224
Stack trace:
#0 /facebook/Facebook/GraphNodes/GraphNodeFactory.php(93): Facebook\GraphNodes\GraphNodeFactory->validateResponseCastableAsGraphNode()
#1 /facebook/Facebook/FacebookResponse.php(289): Facebook\GraphNodes\GraphNodeFactory->makeGraphNode(NULL)
#2 {main}
thrown in /facebook/Facebook/GraphNodes/GraphNodeFactory.php on line 224
Try this instead:
$graphNode = $response->getGraphEdge();
Quite old so i did not mark it as duplicate: FB Graph API query doesn't work in PHP SDK
I am getting this error when i used different user id but working on same user and app secret.
Graph returned an error: Invalid appsecret_proof provided in the API argument
$accessToken = 'XXXXXXXXXXXXXX';
$appsecret_proof = hash_hmac('sha256', $accessToken, app_secret);
$fb = new Facebook\Facebook([
'app_id' => app_id,
'app_secret' => app_secret,
'default_graph_version' => 'v2.11',
'default_access_token' => app_id."|".app_secret
]);
// FacebookSession::enableAppSecretProof(false);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me?fields=adaccounts{name}&appsecret_proof='.$appsecret_proof.'', $accessToken);
} 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;
}
Try it on this
https://developers.facebook.com/tools/explorer/
If you want to provide access_token then that should be in your
It should be like below
https://graph.facebook.com/me?fields=email&access_token=<mytoken>
First try in your developers account, you get the result with access_token and for getting a result you need to provide the fields only.