How to include images in page post API

Viewed 886

I keep getting this error message when am attaching images to page post

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

but when am posting message only, it works fine

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

});
2 Answers

to add multi images to a post in facebook, it has to be done in 2 steps as per facebook

to upload image, refer to this and to make the 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)

    });
}

In order to publish to a page, you will need to use a page access token that has publish_pages permission which you may be missing. You can quickly test the request using the Graph API Explorer tool. You can also use the Access Token Debugger tool to test what permissions your access token has. Also, note that publish_pages permission is reviewable and needs to be approved before you can use it with the general public. Prior to approval, you can only test it with an app where you are an admin and in a page where you have admin role.

Related