Вопрос

I am using RestFb as a java wrapper to make calls to Facebook graph API. I want to post to my fan page as admin. Currently, all posts appear as my personal posts. I have taken the access_code using "manage_pages" as one of the permissions. Here is my code:

public void postOnWall(String wallId, String message, String picture, String link, String linkname, String caption, String description) throws FacebookException {
        facebookClient.publish(wallId+"/feed", FacebookType.class,
                   Parameter.with( "message", message),
                   Parameter.with( "picture", picture), 
                   Parameter.with( "link", link),
                   Parameter.with( "name", linkname),
                   Parameter.with( "caption", caption),
                   Parameter.with( "description", description));
    }

and in my calling method:

try {
            FacebookService facebookService = new FacebookService("access_token");
            facebookService.postOnWall("page_id", comment, "image", "link", title, "caption", description);
        } catch (FacebookException e1) {
            e1.printStackTrace();
        }

I have replaced all parameters in double quotes with the actual values. What else is required?

Это было полезно?

Решение

To post as the page itself you need to use the Page Access Token,

To retrieve this you need to:

  • Obtain the manage_pages permission from the user
  • Access the /me/accounts connection for that user
  • Get the access token for each page from the result of that /me/accounts call
  • Post to /{page id}/feed using the Page Access Token
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top