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
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.....}'
);
Facebook SDK return my Unknown path components but i use this sabe path for cURL and works.
<?php
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed
$fb = new \Facebook\Facebook([
'app_id' => '{APP_ID}',
'app_secret' => '{APP_SECRE}',
'default_graph_version' => 'v6.00',
]);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{GROUP_ID}/members',
'{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;
}
$graphNode = $response->getGraphNode();
?>
I tried several ways but same erros, search but same problem with other people, on cURL query this path works, but are 5K limitation.
Error:
Graph returned an error: Unknown path components: /{MY-GROUP-ID}/members
Thanks for help.
https://developers.facebook.com/docs/graph-api/reference/v6.0/group/members:
This edge was deprecated on April 4th, 2018, and can no longer be used.
You can not request a list of members any more.
on cURL query this path works
You mean something like https://www.facebook.com/groups/{group-id}/members/?
Then you would not be using the API in the first place.
Scraping data this way is not allowed.
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 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.
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.