java - 没有执行操作的授权 - 但该应用程序已获得授权

标签 java facebook-graph-api restfb

我想使用restfb 发布到我的页面之一。我想以页面本身的形式发布,而不是以用户的形式发布到页面墙上。

这是我正在使用的代码:

public class App {
    //user token for accessing the page as admin
    private static final String INITIAL_ACCESS_TOKEN = "#";

    public static void main(String[] args) throws Exception {
        restfb();
    }

    public static void restfb() throws Exception {
        DefaultFacebookClient fbClient;
        Connection myAccounts;
        fbClient = new DefaultFacebookClient(INITIAL_ACCESS_TOKEN, Version.VERSION_2_5);
        myAccounts = fbClient.fetchConnection("me/accounts", Account.class);
        String pageToken = null;
        //retrieve the page token
        for(Object a : myAccounts.getData()) {
            Account account = (Account)a;
            if("MyPage".equals(account.getName())) {
                pageToken = account.getAccessToken();
                break;
            }
        }
        System.out.println(pageToken); //not null here

        //post to the page
        fbClient = new DefaultFacebookClient(pageToken, Version.VERSION_2_5);
        //"me" should refer to the page itself..?
        fbClient.publish("me/feed", FacebookType.class, Parameter.with("message", "Aloha! ;)"));
    }
}

我收到错误

Received Facebook error response of type OAuthException: (#200) The user hasn't authorized the application to perform this action (code 200, subcode null)

我已经访问过此网址:

https://www.facebook.com/dialog/oauth?client_id=###&redirect_uri=###&scope=manage_pages,publish_actions,user_actions:pagealias&response_type=code

它要求我授予我的应用发布和管理我的页面的权限,我授予了它们。

该应用程序不是公开的,因为它是我想用于开发的测试应用程序(因此我没有要求审核)。

我错过了什么?该应用程序还需要哪些其他权限才能工作并正确发布?

最佳答案

您应该请求 publish_pages 权限才能以页面形式发布。 https://developers.facebook.com/docs/facebook-login/permissions#reference-publish_pages

关于java - 没有执行操作的授权 - 但该应用程序已获得授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36162302/

相关文章:

java - 如何通过改造接收来自服务器的消息?

ios - FBSDKGraphRequest 不工作(iOS)

java - 无法使用 Facebook 的 API、使用 MVC 和 Java 发布消息

java - 使用应用程序访问 token 在 Facebook 页面上发帖

java - 发送 "POST"int 列表

java - 选择音量 channel 以在按下音量键时更改

java - 我如何使用 restfb 检索 facebook 授权码

java - Facebook API 是否允许搜索帐户中的个人资料、网络、雇主、学校信息?

java - 使用 RestFB 的安全性如何?

java - ImageIcon 通过使用字符串名称