Facebook Api: How to get a page feed using PHP?

Asked

Viewed 737 times

1

I’m trying to pull the posts from a facebook page and display them on a website, what I need mainly is the photo and caption of each post.

I’m using the following code:

<?php
require_once __DIR__ . '/inc/facebook-php-graph-sdk-5/src/Facebook/autoload.php';
require_once __DIR__ . '/inc/facebook-php-graph-sdk-5/src/Facebook/FacebookRequest.php';

/* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'GET',
  '/{page-id}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
print_r($graphObject);
/* handle the result */
?>

And I’m getting the following mistake:

Fatal error: Class 'FacebookRequest' not found in C:\xampp\htdocs\www\site\wp-content\themes\tema\functions.php on line 7

How am I inserting Faacebookrequest.php and saying that the Class 'Facebookrequest' not found ?

I’ve never done this before and I’m having doubts to begin with, I’m researching and reading the documentation, and yet I’m having trouble understanding the documentation, what’s helping me most are the questions I find in forums and independent articles.

You don’t have to answer everything chewed, if you have a link where I can find the answer I’ll be immensely grateful.

UPDATING:

I kept searching and managed to do as follows, through the documentation of the facebook itself:

<?php
require_once 'inc/facebook-php-graph-sdk-5/src/Facebook/autoload.php';

$fb = new Facebook\Facebook([
  'app_id' => '***********',
  'app_secret' => '*********************',
  'default_graph_version' => 'v2.8',
  ]);

$response = $fb->get('/PAGE-NAME/feed', 'ACCESS-TOKEN-AQUI');

print_r($response);
?>
  • 2

    Take a look at the introduction of the facebook. They use namespaces, so your class invocation would have to look like this: new Facebook\FacebookRequest().

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.