我正在编写一个应用程序来获取用户当前加入的所有组数据。但我不知道为什么它只适用于我的Facebook帐户(应用程序的所有者),对于其他帐户,列表返回null。
这是我用来创建用户登录网址的代码
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();
登录成功时的操作(获取访问令牌):
@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;
}
最后一个是显示组列表的动作:
@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";
}
答案 0 :(得分:1)
user_group
权限是一项扩展权限。因此,要与其他用户使用该应用程序而不是相应应用程序的管理员/测试人员/开发人员,该应用程序需要进入“登录审核”。
见
但你在这里遇到问题:
此权限授予在Facebook尚不可用的平台上构建Facebook品牌客户端的应用程序。例如,Android和iOS应用不会获得此权限的批准。此外,Web,桌面,车载和电视应用程序将不被授予此权限。