我正在使用最新的facebook SDK开发一个Android应用,并且正在使用以下代码从facebook获取一些数据:
public void onFBLoginClick(View view)
{
openActiveSession(this, true, statusCallback);
}
Session.StatusCallback statusCallback = new Session.StatusCallback()
{
@Override
public void call(final Session session, SessionState state, Exception exception)
{
if(session.isOpened())
{
Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
{
@Override
public void onCompleted(GraphUser user, Response response)
{
if(user != null)
{
txtUserName.setText(session.getAccesstoken());
String gender = user.getProperty("gender").toString();
String email = user.getProperty("email").toString();
saveUserData(user.getId(), user.getName(), user.getBirthday(), user.asMap().get("email").toString());
saveAccesstoken(session.getAccesstoken());
getFacebookUserProfilePicture(session.getAccesstoken());
}
}
});
}
}
};
private static Session openActiveSession(Activity activity, boolean allowLoginUI, Session.StatusCallback statusCallback)
{
OpenRequest openRequest = new OpenRequest(activity);
openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
openRequest.setCallback(statusCallback);
Session session = new Session.Builder(activity).build();
if(SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI)
{
Session.setActiveSession(session);
session.openForRead(openRequest);
return session;
}
return null;
}
使用此代码,如何获得朋友列表?还是我必须使用REST API来做到这一点?
解决方法:
您可以签出this link,以了解如何在API 3.0中完成对朋友列表的检索.
希望这可以帮助.