参考: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");
}
}
});
}
}
通过使用上面的代码,我在添加权限后让用户获得额外的东西,如电子邮件、生日等,但没有让朋友额外认为生日。
我在哪里做错了???