Facebook Graph API - How to post to a page?

Asked

Viewed 329 times

2

Good afternoon. I need to know how to adapt the script below for me to post on the page that the logged in user is administrator. For example, if my user is a 3-page admin on the face, I want to post directly from the page and not as if my user had done the post on the page.

Note: I already changed the '/me/photos' by 'page-id/feed' but it appears as a post of mine on the page and not as if the page itself had posted.

FB.login(function () {
                FB.api('/page-id?fields=access_token', 'GET', function (response) {

                    FB.api('/' + response.id + '/photos', 'POST', { message: mensagem, url: imagem }, function (response) {
                        if (!response || response.error) {
                            console.log(response);
                            alert('Error occured');
                        } else {
                            alert('Post ID: ' + response.id);
                        }
                        $("#post-face-action").modal('hide');
                    });

                });

            }, { scope: 'publish_actions, publish_pages, manage_pages' });

1 answer

0

It is necessary to have the permissions:

The id page and access token are requirements. Not tested, but I believe it is important to get the page access token to use on post, and not of the user.

Credits

  • I adjusted my script with these permissions, and added a method that searches the page id to pass to the method it posted, even so goes with my username and not as if the page had posted.

  • I followed the documentation, https://developers.facebook.com/docs/pages/publishing

Browser other questions tagged

You are not signed in. Login or sign up in order to post.