Post something on facebook using facebook4j

440 views Asked by At

I need to post a string on facebook timeline via facebook4j using java. But i am unable to send even a character. I have created an app on facebook for this issue. What i want is just to run a simple java program and that program should post the string on facebook. So that each of my friends should be able to see it as my status. This is my code:

public class FB_Stat_Updator {

    static String appID         = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    static String appSecretKey  = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    static String tok           = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX";


    public static void update_FB_Status(String appID, String appSecretKey) {
        Facebook fb = new FacebookFactory().getInstance();
        fb.setOAuthAppId(appID, appSecretKey);
        /*fb.setOAuthAccessToken(arg0);*/
        fb.setOAuthAccessToken(new facebook4j.auth.AccessToken(tok, null));
        try {
            fb.postStatusMessage("hello everyone");
        } catch (FacebookException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    public static void main(String[] args) {
        FB_Stat_Updator.update_FB_Status(appID, appSecretKey);
    }
1

There are 1 answers

1
Aditya Singh On BEST ANSWER

You need to get an access token for your application from here:

Click here :D

Do not forget to give your app the permissions. :D