从我的应用程序中,我需要在Facebook页面的相册中发布图像。
根据resfb文档,我正在实现OAuth流。特别是,我以这种方式创建了登录url:
FacebookClient client = new DefaultFacebookClient(Version.VERSION_2_12);
String loginDialogUrlString = client.getLoginDialogUrl(APP_ID, REDIRECT_URL, scopeBuilder);
但现在我无法理解我要创建页面访问令牌。
我试过使用这个:
AccessToken accessToken = client.obtainUserAccessToken(APP_ID, APP_SECRET, REDIRECT_URL, verificationCode); // verification code from the the previous login
但是当我尝试使用这个(USER(访问令牌在我的页面上发布内容时,我会得到这个错误:
com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: (#210) A page access token is required to request this resource. (code 210, subcode null) 'null - null'
那么,获取PAGE访问令牌的正确方法是什么?
注意我使用此代码发布照片:
byte[] imageAsBytes = fetchBytesFromImage();
JsonObject obj = client.publish(
"mypage",
JsonObject.class,
BinaryAttachment.with("cat.jpg", imageAsBytes, "image/jpeg"),
Parameter.with("message", "A cat")
);
使用使用用户访问令牌创建的FacebookClient
,您可以调用:
Connection<Account> connection = client.fetchConnection("/me/accounts", Account.class);
然后对连接进行迭代,就可以访问用户管理的页面的所有页面访问令牌。