我正在开发日历应用程序,我想从Facebook获取即将到来的生日,所以我读到它并发现我需要使用Facebook的Graph API资源管理器创建应用程序,我做了,但它不起作用对于我,当我尝试获取我的朋友列表时,我只得到一个空列表,这是我使用的代码, 没有错误,但列表是空的。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String code = request.getParameter("code");
String URLEncodedRedirectURI = URLEncoder.encode("http://localhost:8084/facebookfriends/FriendsListServlet");
String MY_ACCESS_TOKEN = "";
String authURL = "https://graph.facebook.com/oauth/access_token?"
+ "client_id=" + FriendsListServlet.APP_ID + "&"
+ "redirect_uri=" + URLEncodedRedirectURI + "&"
+ "client_secret=" + FriendsListServlet.APP_SECRET + "&"
+ "code=" + code;
URL url = new URL(authURL);
String result = readURL(url);
String[] pairs = result.split("&");
for (String pair : pairs) {
String[] kv = pair.split("=");
if (kv[0].equals("access_token")) {
MY_ACCESS_TOKEN = kv[1];
}
}
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN, FriendsListServlet.APP_SECRET);
Connection<User> friends = null;
try {
User loginUser = facebookClient.fetchObject("me", User.class);
request.setAttribute("loginUser", loginUser);
friends = facebookClient.fetchConnection("/me/friends", User.class);
} catch (FacebookException e) {
e.printStackTrace();
}
List<User> friendsList = friends.getData();
int count = friendsList.size();
request.setAttribute("friendsList", friendsList);
request.getRequestDispatcher("FriendsList.jsp").forward(request, response);
}
答案 0 :(得分:2)
如果没有他们使用您的应用,您将无法再获得朋友生日。通过图谱API的引入,friends_*
权限已被删除。
见