Facebook Graph API error - Unknown path components - php

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.....}'
);

Related

Facebook Workplace PHP SDK Unknown path components

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.

how to publish on pages and groups where facebook where I granted php API permission

Friends, I have a problem that is spinning around me. I am learning to use the Facebook API, I have 24 hours with this and I am already understanding how it works, I feel a little sorry because in reality it is easy the problem is that I do not understand much English so it is difficult for me.
The specific question is: How do I automatically publish in the selected groups and pages when I log in with Facebook? For example, of the following groups that I manage, I only select one.
The problem is that when the group is posted, the group id is necessary, using this code snippet.
$response = $this->fb->post('/123456789/feed', $linkData, $accessToken);
So? The specific question, How do I get that list of groups (and also for the pages) to which I granted permission to be able to (it occurs to me), go through an array and do the post automatically.
Right now I am clear about the following points:
1.- I need to create an app: https://developers.facebook.com/
2.- Have the Facebook SDk installed: https://github.com/facebook/php-graph-sdk
3.- My class has saved these permissions and this configuration:
require_once "/../vendor/autoload.php";
class facebookController{
private $appid ='XXXXX';
private $appsecret='XXXXXXXXXXXXXXXXXXXXXXXXXX';
public $fb;
public $helper;
public $permisos = ['email', 'manage_pages', 'publish_pages' , 'publish_to_groups', 'user_posts', 'groups_access_member_info'];
public $callbackurl = 'http://localhost/misitio.com.mx/auth/fb-callback.php';
public $loginurl;
function __construct(){
$this->fb = new Facebook\Facebook([
'app_id' => $this->appid,
'app_secret' => $this->appsecret,
'default_graph_version' => 'v3.2',
]);
$this->helper = $this->fb->getRedirectLoginHelper();
$this->loginurl = $this->helper->getLoginUrl($this->callbackurl, $this->permisos);
}
}
4.- I must obtain the Access Token, it can be debugged here: https://developers.facebook.com/tools/explorer?method=GET&path=me%3Ffields%3Did%2Cname&version=v3.2
$this->helper = $this->fb->getRedirectLoginHelper();
try {
$accessToken = $this->helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
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;
}
5.- For some cases I need the user_id, I already have it saved:
$oAuth2Client = $this->fb->getOAuth2Client();
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
$userid = $tokenMetadata->getUserId();
6.- To post for example in a group, I use the following and this is where the inconvenience is: (Based on the official documentation: https://developers.facebook.com/docs/graph-api/reference/v3. 2 / user / groups)
public function toPost($titulo, $url){
$empresa = new configuracionController();
$userid=$empresa->getFbUserId();
$accessToken = $empresa->getFBToken();
try {
// Returns a `Facebook\FacebookResponse` object
$this->fb->post('/123456789/feed', $url, $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;
}
$graphNode = $response->getGraphNode();
}
From already thank you very much.

Graph returned an error: Invalid appsecret_proof provided in the API argument in facebook sdk v5

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.

Is possible to get facebook user access token without user interaction?

I want that my Php script (myscript.php ) that i have deployed on a public host gets the Facebook user access token (with my facebook account) from Facebook. I don't want user interaction with login procedure where to inser user and pass. Is it possibile and how can be made? I understand the SDK is not useful for this scenario.
For now my script is:
require_once ('../php-graph-sdk-5.x/src/Facebook/autoload.php');
$fb = new \Facebook\Facebook([
'app_id' => 'myappid',
'app_secret' => 'mysecret',
'default_graph_version' => 'v2.10',]);
$helper = $fb->getRedirectLoginHelper();
$accessTokenEntity=$helper->getAccessToken();
try {
$accessTokenEntity=$helper->getAccessToken();
$response = $fb->get('/me', $accessTokenEntity->getValue());
}
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;
}
$me = $response->getGraphUser();
echo 'Logged in as ' . $me->getName();
Copied from gitub example but i think it s not good for my scenario.
And the output is
"Fatal error: Call to a member function getValue() on null in ..."

PHP - Graph API 2.8 not requesting email

I'm integrating FB login on my website and for that I need the email of the user. Here's part of the code
$fb = new Facebook\Facebook([
'app_id' => 'app-id',
'app_secret' => 'secret',
'default_graph_version' => 'v2.8',
]);
$helper = $fb->getJavaScriptHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
if (isset($accessToken)) {
$fb->setDefaultAccessToken($accessToken);
try {
$requestProfile = $fb->get("/me?fields=name,email");
$profile = $requestProfile->getGraphNode()->asArray();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
print_r($profile);
}
What I'm getting back is name and id. Even the popup that requests users to grant permissions to the app doesnot ask for the email. And understandably it doesn't return it as well.
I've seen this and many other questions but none of the solutions have worked for me. What am I doing wrong?
You need to request permission to obtain the user email.
Please review https://developers.facebook.com/docs/php/howto/example_facebook_login to see how to request it (e.g.: permissions = ['email', 'user_likes', 'user_location', 'user_friends', 'user_birthday', 'user_hometown'];)
Refer to https://developers.facebook.com/docs/facebook-login/permissions for the permission reference and https://github.com/thephpleague/oauth2-facebook for more example.
Thanks to CBroe who pointed this out in the comments above, the permissions were supposed to be set in the javascript, not the php. It's because the php code is run when the authorization is complete and you have received all information you were supposed to.
To fix it, I changed
FB.login(function(response){
// take action based on response
});
To
FB.login(function(response){
// take action based on response
}, {scope: 'public_profile, email'});
And it works now. Thanks

Categories