java - 使用restfb获取页面访问令牌的正确方法是什么?
问题描述
从我的应用程序中,我需要在 Facebook 页面的相册中发布图像。
在 resfb 文档之后,我正在实施 OAuth 流程。特别是我以这种方式创建了登录网址:
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
用户访问令牌创建的 a ,您可以调用:
Connection<Account> connection = client.fetchConnection("/me/accounts", Account.class);
然后遍历连接,您可以访问用户管理的页面的所有页面访问令牌。
推荐阅读
- r - 修改/添加列到嵌套 tibble
- angular-dart - AngularDart 材质颜色主题
- ios - Stack View 大小变化无法可视化
- webpack - 如何使用 vue-cli 安装其他 vue 版本不是最新的
- javascript - 从 PHP while 循环中随机化 jquery 中“DIV”的边框颜色
- android - 为 FrameLayout 内的所有自定义视图触发 OnClickListener
- c# - C#:在转换泛型类型时,为什么需要对象?
- amazon-web-services - 在 AWS 服务中存储特定于环境的配置变量时,我该怎么做?
- android - 如何在应用程序自动退出时获取通知并在关闭时清理数据
- javascript - Three.js - 通过鼠标移动和点击创建/更新网格