0

我正在努力从我们网站上的 FB 页面发布帖子。我们添加到我们的 FB 页面的每个新帖子和照片也需要在我们的网站上显示。

我有这段代码,但没有按我的需要工作。

require 'php-graph-sdk-5.x/src/Facebook/autoload.php';

$fb = new Facebook\Facebook([
    'app_id' => '...',
    'app_secret' => '{app-secret}', // don't know where to find app_secret for my page, I've found that just for apps, not pages
    'default_graph_version' => 'v2.10'
]);

$access_token = '...'; // generated in developers, but with just for 12 hours, than this token is expired... :-(

try {
    // Returns a `Facebook\FacebookResponse` object
    $response = $fb->get('me?fields=id,name,feed,data', $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();

foreach ($graphNode as $node) {
    foreach ($node as $items) {
        print_r($items);

        // when access token was valid, I got posts from out FB page. But with no images, didn't find how to get add images to this feed...
    }
}

所以,我的问题是:

  1. 在哪里可以找到 FB 页面的 app-secret?没有那个我无法连接到我的 FB 页面,我想

  2. 如何生成永久访问令牌,或者如果不可能,如何以其他方式制作我?

  3. 如何将图像(新的、共享的等)添加到我的提要?

谢谢。

4

1 回答 1

1
  1. 每个页面没有 App Secret,每个 App 只有 App Secret。您可以在应用程序设置中找到它。
  2. 扩展/永久令牌:https ://developers.facebook.com/docs/facebook-login/access-tokens/或http://www.devils-heaven.com/facebook-access-tokens/ - 用于获取提要条目不受限制的页面,您可以只使用应用程序访问令牌,您可以在 PHP 代码中对其进行硬编码。
  3. 在提要中获取图像,而不仅仅是消息:您需要指定要获取的字段,否则您只会获取默认字段。它被称为“声明性字段”:https ://developers.facebook.com/docs/graph-api/changelog#v2_4 - 另外,请查看 API 参考:https ://developers.facebook.com/docs/graph- api/参考/帖子
于 2017-10-12T08:47:06.167 回答