无法使用其 PHP SDK 在 Facebook 页面上自动 post

Unable to auto post on a Facebook Page using its PHP SDK

我在很多地方看到,Facebook 在 2018 年左右进行了一些更改,以防止人们 post 使用 PHP 作为页面。我研究了一段时间,看看如果我是它的管理员,我是否仍然可以在 Facebook 页面上自动 post。

我的消息来源: and https://adamboother.com/blog/automatically-posting-to-a-facebook-page-using-the-facebook-sdk-v5-for-php-facebook-api/

我是唯一一个会使用这个自动 post 应用程序的人,我是我将 post 添加这些链接的页面的管理员。

这是我试过的代码:

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

$pageAccessToken = "page_access_token";


$linkData = [
    'link' => 'some_link',
    'message' => 'some_message'
];
try {
    $response = $fb->post('/me/feed', $linkData, $pageAccessToken);
} 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();

运行上面的代码,我得到以下错误:

Graph returned an error: (#200) If posting to a group, requires app being installed in the group, and \ either publish_to_groups permission with user token, or both manage_pages \ and publish_pages permission with page token; If posting to a page, \ requires both manage_pages and publish_pages as an admin with \ sufficient administrative permission.

现在,我是页面的管理员。我还在权限中选择了 manage_pagespublish_pages。那么,为什么我会收到此错误?

您很可能使用的不是页面令牌,而是用户令牌。它仍然有效,但您必须使用页面令牌 post 到页面。

根据文档 here, you can not publish posts by using the feed edge anymore. This 文档讨论了编辑和删除帖子,它还说我们不能创建新帖子。

2020 年 5 月 5 日,Facebook 发布了六个新的页面权限,以取代 manage_pages 和 publish_pages 权限。利用 curl,您可以使用 php 创建和更新 post 或评论,回复 post 或评论,以及删除 post 或评论,在您的Facebook 页面 Feed 作为页面。

  • 向 /{page-id}/feed 端点发送 POST 请求:

    curl -i -X POST "https://graph.facebook.com/{page-id}/feed ?message=粉丝们好! &access_token={页面访问令牌}"

  • 成功后,您的应用会收到以下响应:

    { "id": "{page-post-id}" }

来源:https://developers.facebook.com/docs/pages/publishing/