可能重复:
Android: How to get friends birth dates from facebook calendar using Graph API
请参阅:https://stackoverflow.com/a/13926065/1770916
我设置获取朋友生日和列表的权限。代码如下。
private void signInWithFacebook() {
mSessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
}
}, null, false);
String applicationId = Utility.getMetadataApplicationId(getBaseContext());
mCurrentSession = mSessionTracker.getSession();
if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
mSessionTracker.setSession(null);
Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
Session.setActiveSession(session);
mCurrentSession = session;
}
if (!mCurrentSession.isOpened()) {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(MainActivity.this);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList("user_birthday", "email", "user_location", "friends_birthday","read_friendlists" ));
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
mCurrentSession.openForRead(openRequest);
}
}
}
但我只收到朋友ID和姓名。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
if (mCurrentSession.isOpened()) {
Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
Log.d("AL", user.getId() + " " + user.getName() + " " + user.getInnerJSONObject());
}
});
Request.executeMyFriendsRequestAsync(mCurrentSession, new Request.GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users, Response response) {
Log.d("AL",""+response.toString());
for (int i=0;i<users.size();i++){
Log.d("AL",""+users.get(i).toString());
welcome.setText("Done");
}
}
});
}
}
通过使用上面的代码,我会在添加权限后向用户提供其他内容,例如电子邮件,生日等,但不会让其他朋友认为是生日。
我做错了?
答案 0 :(得分:5)
要获取好友信息,我们需要HttpConnection
来关注url
"https://graph.facebook.com/me/friends?access_token="+ mAccessToken + "&fields=id,first_name,last_name,location,picture,birthday");
此处添加您需要的字段。 我认为它会起作用..
答案 1 :(得分:0)
这里我们得到了任何东西
String url = "https://graph.facebook.com/me/friends?fields=birthday,name&access_token="+ facebook.getAccessToken();
使用这个iam过生日
JSONObject JOAlbums = JAAlbums.getJSONObject(i);
String date = DaysCount(JOAlbums.getString("birthday"));