如何在页面 post API 中包含图像

How to include images in page post API

我在将图像附加到页面时不断收到此错误消息 post

message: '(#10) Application does not have permission for this action'

但是当我 post 只发送消息时,它工作正常

FB.api('PAGE_ID/feed', 'post', {
    message: 'Message is here',
    link: 'https://my_LINK.com',
    "child_attachments": [
        {
            "link": "https://1.jpg",
            "image_hash": "hash1",
            "name": "Some Name",
            "description": "Some description"
        },
        {
            "link": "https://2.jpg",
            "image_hash": "hash2",
            "name": "Some Name",
            "description": "Some description 2"
        }]

}, function (res) {
    if (!res || res.error) {
        console.log(!res ? 'error occurred' : res.error);
        return;
    }

});

为了发布到页面,您需要使用具有 publish_pages 权限的页面访问令牌,您可能缺少该权限。 您可以使用 Graph API Explorer tool 快速测试请求。 您还可以使用 Access Token Debugger 工具来测试您的访问令牌具有哪些权限。 此外,请注意 publish_pages 权限是 reviewable and needs to be approved,然后才能将其与一般 public 一起使用。在批准之前,您只能使用您是管理员的应用程序和您具有管理员角色的页面对其进行测试。

要将多张图片添加到 Facebook 中的 post,必须按照 facebook

分两步完成

上传图片参考this 制作post

function post_fb_ad(description, ad_images) {

    attached_media = []
    for (var adImg of ad_images) {

        attached_media.push({ media_fbid: adImg.id })
    }

    FB.api('page_id/feed', 'post', {
        message: description,
        attached_media: attached_media,
        access_token: EXD_ACCESS_TOKEN


    }, function (res) {
        if (!res || res.error) {
            console.log(!res ? 'error occurred' : res.error);
            return;
        }

        console.log('post id is ', res)

    });
}