Facebook。 Post 将自己的 facebook 页面作为页面

Facebook. Post to own facebook page as page

我想在用户在我的网站上创建文章后自动post到我自己的 Facebook 页面作为页面而不是用户。

首先:是否可以在没有用户授权的情况下这样做?

我已经试过了:

FB.api(
            "/page_id/feed",
            "POST",
            {
                'access_token': pageAccessToken,
                "message": "This is a test message"
            },
            function (response) {
                console.log(response);
            }
        );

但是出现用户未授权的错误。也许有解决方法并自动 post 到我自己的 Facebook 页面?

为了得到这个消息

{
  "error": {
    "message": "(#200) The user hasn't authorized the application to perform this action", 
    "type": "OAuthException", 
    "code": 200
  }
}

这意味着您没有为会话用户授予 publish_actions 权限。

您在此过程中的某个时刻需要用户授权,然后扩展用户令牌。参见 https://developers.facebook.com/docs/roadmap/completed-changes/offline-access-removal#extend_token

获得扩展令牌后获取页面令牌,该令牌不会过期。

参考:https://developers.facebook.com/docs/graph-api/reference/v2.2/page/feed

A page access token with publish_actions permission can be used to publish new posts on behalf of that page.