phpfacebookfacebook-graph-apifacebook-access-tokenapp-secret

Get Facebookpageposts on website


I'm trying to get an overview of all the posts op a facebook page in my website. But I get a Invalid appsecret_proof provided message.When I try it in the Graph API Explorer everything works fine but when I try it in my testplace it doesn't work. I'm wondering if there is just some kind of internetconnection problem or I've done something wrong with my code/token.

<?php
  require_once 'application/third_party/Facebook/autoload.php';
  $fb = new \Facebook\Facebook([
    'app_id' => '<app-id>',
    'app_secret' => '<app-secret>',
    'default_graph_version' => 'v2.10',
  ]);

  try {
    // Returns a `FacebookFacebookResponse` object
    $response = $fb->get(
      '/<page-id>/feed',
      '{<access-token>}'
    );
  } 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();

    foreach ($graphNode['data'] as $post): ?>
      <section class="bg-primary">
        <div class="container">
          <div class="row">
            <div class="col-lg-8 mx-auto text-center">
              <h2 class="section-heading text-white">Verslag: <?php echo $post['created_time']; ?></h2>
              <hr class="light">
              <p class="text-faded"><<?php echo $post['message']; ?></p>
            </div>
          </div>
        </div>
      </section>
    <?php endforeach; ?>

Solution

  • It's like Ceejayoz says, my page and my app were not linked and that's why I got a invalid appsecret message. I also got some troubles with linking the page and my app, but this question got answered here.