【发布时间】:2016-03-22 18:24:13
【问题描述】:
我想使用 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! ;)"));
}
}
我收到错误
收到 OAuthException 类型的 Facebook 错误响应:(#200) 用户尚未授权应用程序执行此操作(代码 200,子代码为空)
我已经访问过这个网址:
https://www.facebook.com/dialog/oauth?client_id=###&redirect_uri=###&scope=manage_pages,publish_actions,user_actions:pagealias&response_type=code
它要求我授予我的应用发布和管理我的页面的权限,我授予了它们。
该应用程序不公开,因为它是我想用于开发的测试应用程序(所以我没有要求审核)。
我错过了什么?该应用还需要哪些其他权限才能正常工作和发布?
【问题讨论】:
标签: java facebook-graph-api restfb