无法使用Java在我的Facebook墙上张贴

时间:2019-04-11 05:06:33

标签: java facebook-graph-api facebook-access-token facebook-oauth restfb

我正在尝试使用Java在我的Facebook墙上张贴一条消息。我已标记所有权限。但我收到异常“ FacebookOAuthException”。请帮助解决此问题。预先感谢!

package com.java.sample.workouts;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.Parameter;
import com.restfb.Version;
import com.restfb.types.FacebookType;
import com.restfb.types.User;
import com.sun.media.jfxmedia.logging.Logger;

public class PostInFBWall {

    public static void updateStatus(String message) {
        FacebookClient facebookClient= new DefaultFacebookClient("access token", Version.LATEST);
         facebookClient.publish("me/feed", FacebookType.class,
                 com.restfb.Parameter.with("message", message));
    }

    public static void main(String[] args) {
        PostInFBWall.updateStatus("FB testing");
    }
}

facebook权限的屏幕截图是:

Facebook permissions

eclipse中的例外是:

Exception in thread "main" com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: (#200) If posting to a group, requires app being installed in the group, and \
      either publish_to_groups permission with user token, or both manage_pages \
      and publish_pages permission with page token; If posting to a page, \
      requires both manage_pages and publish_pages as an admin with \
      sufficient administrative permission (code 200, subcode null)
at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1199)
at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1116)
at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1057)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:979)
at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:453)
at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:478)
at com.java.sample.workouts.PostInFBWall.updateStatus(PostInFBWall.java:35)
at com.java.sample.workouts.PostInFBWall.main(PostInFBWall.java:52)

1 个答案:

答案 0 :(得分:0)

无法再将消息或照片发布到用户墙上,所需的权限本来是publish_actions,但已弃用。