Facebook Workplace PHP SDK Unknown path components - php

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.

Related

Facebook Graph API error - Unknown path components

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

What is the access token in Facebook PHP SDK?

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.

Facebook login with php grapth sdk gives a 404 error

I have a facebook login button on a site, which used to work. I haven't changed anything as far as I know, but now it just gives a Not Found error:
The requested URL /https://www.facebook.com/v3.0/dialog/oauth was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Not sure if it would help, but this is in my fbConfig.php file:
require_once __DIR__ . '/facebook-php-sdk/autoload.php';
// Include required libraries
use Facebook\Facebook;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookSDKException;
//some code to set the correct $appId and $appSecret that developers.facebook gave me
$redirectURL = $url; //Callback URL
$fbPermissions = array('email'); //Optional permissions
$fb = new Facebook(array(
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v3.0',
));
// Get redirect login helper
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state']=$_GET['state'];
// Try to get access token
try {
if(isset($_SESSION['facebook_access_token'])){
$accessToken = $_SESSION['facebook_access_token'];
}else{
$accessToken = $helper->getAccessToken();
}
} catch(FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
A cursory glance at The PHP Docs indicates the current default_graph_version version is v2.2. So that means 1 of 2 things:
You're using a version that doesn't exist
You're using a beta version which is caveat emptor
Try bringing the version back to v2.2 and seeing if it works. Also ensure you're using an up-to-date, unmodified, official version of their SDKs.

Failing to get an Facebook App to post to a Page's Wall, as that Page

I am struggling going round in circles getting an Facebook App to post to a Page's Wall, as that Page.
** Note: I put out a 300 point bounty to update an outdated answer of a related, well-viewed, existing question. Happy to award anyone who also answers there with the updated, working, solution
In brief:
I have the App Secret and ID
I have Page ID
I am relying on an in-code approach to generating the token I need.
It is based on a solution I saw posted on the SDK GitHub page but it does not work
I am using API v 2.9
I am using the latest PHP SDK
It's just been hard.
The solution I used is purely based on the one below:
<?php
define('FACEBOOK_SDK_V4_SRC_DIR', __DIR__ . '/Facebook');
require_once __DIR__ . '/Facebook/autoload.php';
use Facebook\FacebookRequest;
$app_id = {{your app-id}};
$app_secret = {{your app-secret}};
$fb = new Facebook\Facebook([
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => '{{your app-version}}',
]);
$token = $fb->get(
'/oauth/access_token?client_id=' . $app_id . '&'.
'client_secret=' . $app_secret . '&'.
'grant_type=client_credentials');
$get_token = $token -> getdecodedBody();
$access_token = $get_token['access_token'];
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/{{your facebook 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;
}
$body = $response->getBody();
print_r($body);
?>
I am certainly not lazy. I have been stuck on this issue for weeks.
I have tried the following different solutions and have gotten stuck in either a permissions related issue that was also related to depracated functionality and API calls or getting the right token to do it.
Posting to a facebook page from a website using curl (using a pure CURL approach - "The user hasn't authorized the application to perform this action")
Facebook SDK returned an error: You must provide an access token. Php Facebook Api - (suggests that I support login and redirection callback - yet I do not want any user intervention everytime when posting onto the page)
Graph returned an error: Invalid appsecret_proof provided in the API argument - Previous attempt was based on this example but the appsecret-proof issue
Simple example to post to a Facebook fan page via PHP? - Another CURL-based approach that failed me
https://stackoverflow.com/a/14212125/919426 - Best explained step by
step process for permissions and tokens, but still failed
Update:
Tried the following and got the error "Invalid appsecret_proof provided in the API argument"
$fb = new Facebook([
'app_id' => 'APP_ID',
'app_secret' => 'APP_SECRET',
'default_graph_version' => 'v2.9',
]);
$postData = [
'message' => "Test Message",
'picture' => 'https://www.website.com/image.jpg'
];
try
{
// 'LONG_LIVED_PAGE_ACCESS_TOKEN' obtained by going to https://developers.facebook.com/tools/debug/accesstoken and clicking
// "Extend Access Token"
$response = $fb->post('/' . 'PAGE_ID' . '/feed', $postData,"LONG_LIVED_PAGE_ACCESS_TOKEN");
}
catch (FacebookResponseException $e)
{
var_dump("Facebook Response Exception occured: \n" . $e);
exit;
}
catch(FacebookSDKException $e)
{
var_dump("Generic Facebook SDK Exception occured: \n" . $e);
exit;
}
catch(Exception $e)
{
var_dump("Uknown Exception occured while attempting to call the Facebook SDK API: \n" . $e);
exit;
}
There are countless more that I have tried and failed.

Get Facebook Pages likes total_count (PHP, Facebook Graph API)

I try to get the total number of likes for different Facebook pages, like this one for example : https://www.facebook.com/LeoMessi/
I have implemented the following code :
<?php
// Pass session data over.
session_start();
// Include the required dependencies.
require_once( 'vendor/autoload.php' );
// Initialize the Facebook PHP SDK v5.
$fb = new Facebook\Facebook([
'app_id' => '**********',
'app_secret' => '**********',
'default_graph_version' => 'v2.9',
]);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/176063032413299?fields=likes.limit(0).summary(true)', $_SESSION['access_token']);
var_dump($response);
} 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;
}
It works, but it does not return the total_count property. I don'to how to access this property for any Facebook Page. Could you help me ?
Ok everybody, I just founded the solution just after having posted my question. And the solution is just here : Request to get total count of Facebook page likes in v2.3 API
To get the number of fans, you now need to use fields=fan_count.
So I just replace
/176063032413299?fields=likes.limit(0).summary(true)
With
/176063032413299?fields=fan_count
And it returns
["fan_count"]=> int(88899488)
Hope this can help someone else.
Modify field as :
{page-id}?fields=fan_count

Categories