Posting status message to facebook page

242 views Asked by At

Im trying to post some status message on my facebook page, not my personal facebook profile account, but on page i created separately.

My current code looks like this:

import facebook4j.Facebook;
import facebook4j.FacebookException;
import facebook4j.FacebookFactory;
import facebook4j.Post;
import facebook4j.ResponseList;
import facebook4j.conf.Configuration;
import facebook4j.conf.ConfigurationBuilder;

public class FacebookImpl {

// from https://developers.facebook.com/apps/
static String appId = "11removed";

// from https://developers.facebook.com/apps/
static String appSecret = "c0removed";

// from https://developers.facebook.com/tools/accesstoken/
static String appToken = "11removed";

// my facebook page
static String myFaceBookPage = "niremoved";

public static void main(String[] args) throws FacebookException {

    // Make the configuration builder
    ConfigurationBuilder confBuilder = new ConfigurationBuilder();
    confBuilder.setDebugEnabled(true);

    // Set application id, secret key and access token
    confBuilder.setOAuthAppId(appId);
    confBuilder.setOAuthAppSecret(appSecret);
    confBuilder.setOAuthAccessToken(appToken);

    // Set permission
    // https://developers.facebook.com/docs/facebook-login/permissions
    confBuilder.setOAuthPermissions("manage_pages,publish_pages,publish_actions");
    confBuilder.setUseSSL(true);
    confBuilder.setJSONStoreEnabled(true);

    // Create configuration object
    Configuration configuration = confBuilder.build();

    // Create FacebookFactory and Facebook instance
    FacebookFactory ff = new FacebookFactory(configuration);
    Facebook facebook = ff.getInstance();

    // this one works fine
    System.out.println(getFacebookPostes(facebook, myFaceBookPage));

    // try to post status
    // FacebookException{statusCode=403, errorType='OAuthException', 
    // errorMessage='(#200) The user hasn't authorized the application to perform this action', errorCode=200, errorSubcode=-1, version=2.4.5}
    facebook.postStatusMessage(myFaceBookPage, "Test Facebook4J.");

}

public static String getFacebookPostes(Facebook facebook, String page) throws FacebookException {
    ResponseList<Post> results = facebook.getPosts(page);
    // as example just to see if i get any data
    return results.get(0).getMessage();
}

}

Problem is that i cant post any message on page using this code: facebook.postStatusMessage(myFaceBookPage, "Test Facebook4J."); but i can get messages already posted (via facebook web interfaces) with method getFacebookPostes.

Can anyone help me with this one ? And please do not paste some random dev.Facebook link to look into API.

What i did: - create app on https://developers.facebook.com/apps/ i have appid, appsecret

Thanks

0

There are 0 answers