[英]Java: get list of group on facebook using RestFB
I'm writing an application to get all group data that the user currently joining. 我正在编写一个应用程序以获取用户当前加入的所有组数据。 But i don't know why it's only working for my facebook account (owner of app, too), for other account, the list return null.
但是我不知道为什么它仅适用于我的facebook帐户(也是应用程序的所有者),对于其他帐户,列表返回null。
This is the code i use to create url for user to login 这是我用来创建用户登录网址的代码
AppInfo appInfo = new AppInfo();
String appId = appInfo.getAppId();
String redirectUrl = URLEncoder.encode(appInfo.getRedirectUrl(), "utf-8");
List<String> list = appInfo.getPermission();
StringBuilder builder = new StringBuilder();
for(String permission : list){
if(builder.length() > 0)
builder.append(",");
builder.append(permission);
}
String url = "https://graph.facebook.com/oauth/authorize?display=popup&client_id="+appId+
"&redirect_uri="+redirectUrl+"&scope="+builder.toString();
Action when login success (get the access token): 登录成功时的操作(获取访问令牌):
@RequestMapping(value="/success")
public ModelAndView success(@RequestParam(value = "code") String authorizationCode) throws IOException{
AppInfo appInfo = new AppInfo();
String appId = appInfo.getAppId();
String secretKey = appInfo.getAppSecret();
String redirectUrl = URLEncoder.encode(appInfo.getRedirectUrl(), "utf-8");
WebRequestor wr = new DefaultWebRequestor();
WebRequestor.Response accessTokenResponse = wr.executeGet(
"https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&redirect_uri=" + redirectUrl
+ "&client_secret=" + secretKey + "&code=" + authorizationCode);
FacebookClient.AccessToken token = DefaultFacebookClient.AccessToken.fromQueryString(accessTokenResponse.getBody());
String accessToken = token.getAccessToken();
ModelAndView mav = new ModelAndView();
mav.setViewName("success");
mav.addObject("authorizationCode", authorizationCode);
mav.addObject("accessToken", accessToken);
return mav;
}
And the last is Action to display list of group: 最后是显示组列表的操作:
@RequestMapping(value="/facebookData", method=RequestMethod.POST)
public String autoFacebook(@RequestParam("accessToken") String accessToken, Model model){
FacebookClient fbClient;
Post firstGroupPost = null;
fbClient = new DefaultFacebookClient(accessToken, Version.VERSION_2_3);
Connection<Group> group = fbClient.fetchConnection("me/groups", Group.class);
if(!group.getData().isEmpty()){
Group firstGroup = group.getData().get(0);
Connection<Post> groupPost = fbClient.fetchConnection(firstGroup.getId()+"/feed", Post.class);
firstGroupPost = groupPost.getData().get(0);
}
model.addAttribute("firstGroupPost", firstGroupPost);
model.addAttribute("group", group);
return "facebook";
}
The user_group
permission is an extended permission. user_group
权限是扩展权限。 Therefore, to use it with another user than an admin/tester/developer of the respective app, the app need to go under Login Review. 因此,要将其与相应应用程序的管理员/测试人员/开发人员以外的其他用户一起使用,则该应用程序需要进入“登录查看”。
See 看到
But you'll have a problem here: 但是您这里会遇到问题:
user_groups
) user_groups
) This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available.
此权限授予在尚不可用Facebook的平台上构建Facebook品牌客户端的应用程序。 For example, Android and iOS apps will not be approved for this permission.
例如,Android和iOS应用程序将不会获得此权限。 In addition, Web, Desktop, in-car and TV apps will not be granted this permission.
此外,不会向Web,桌面,车载和电视应用授予此权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.