【问题标题】:Get Facebookpageposts on website在网站上获取 Facebookpageposts
【发布时间】:2018-07-19 03:52:00
【问题描述】:

我正在尝试了解我网站上 Facebook 页面上所有帖子的概览。 但是我收到一条无效的 appsecret_proof 提供的消息。当我在 the Graph API Explorer 中尝试时,一切正常,但是当我在我的测试场所尝试时,它不起作用。我想知道是否只是某种互联网连接问题,或者我的代码/令牌做错了什么。

<?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; ?>

【问题讨论】:

  • 您确实删除了实际访问令牌值周围的花括号,对吧...?
  • 是的,现在我又试了一次,我收到了另一条错误消息(我猜是由于缓存问题)。它说它与我的 appsecret_proof 有关。消息:API 参数中提供的 appsecret_proof 无效。
  • 这意味着您的应用 ID 或应用密码错误,或者您的访问令牌不是来自正确的应用。如果您从 Graph API Explorer 获得令牌,它可能与默认的 Graph Explorer 应用相关联,不是您的应用。

标签: php facebook facebook-graph-api facebook-access-token app-secret


【解决方案1】:

就像 Ceejayoz 所说,我的页面和我的应用程序没有链接,这就是我收到无效 appsecret 消息的原因。我在链接页面和我的应用时也遇到了一些麻烦,但这个问题得到了回答 here

【讨论】:

    猜你喜欢
    • 2015-03-16
    • 2014-04-09
    • 1970-01-01
    • 2013-10-28
    • 2016-07-25
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 2022-08-22
    相关资源
    最近更新 更多