简体   繁体   English

使用facebook4j在facebook上发布内容

[英]Post something on facebook using facebook4j

I need to post a string on facebook timeline via facebook4j using java. 我需要使用Java通过facebook4j在facebook时间轴上发布字符串。 But i am unable to send even a character. 但是我什至无法发送一个字符。 I have created an app on facebook for this issue. 我已经在Facebook上为此问题创建了一个应用程序。 What i want is just to run a simple java program and that program should post the string on facebook. 我想要的只是运行一个简单的Java程序,该程序应该在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);
    }

You need to get an access token for your application from here: 您需要从此处获取应用程序的访问令牌:

Click here :D 点击这里:D

Do not forget to give your app the permissions. 不要忘记为您的应用授予权限。 :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM