我正在使用Facebook SDK(facebook-android-sdk-3.16)并尝试检索用户的public_profile信息。
但是当我尝试获得用户生日时,它总是让我为空
这是我的代码:
public void onClick(View view) {
openActiveSession(_mActivity, true, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Log.v(APP_TAG, " ============== " + session.getPermissions());
Log.v(APP_TAG, " ============== " + session.isPermissionGranted("user_birthday"));
//make request to the /me API);
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
Log.d(APP_TAG, " ============== " + response);
if (user != null) {
_medtFName.setText(user.getFirstName());
_medtLName.setText(user.getLastName());
_medtEmailAddress.setText(user.getProperty("email").toString());
Log.i(APP_TAG, " ============== " + user.getBirthday());
Log.i(APP_TAG, " ============== " + user.getProperty("gender").toString());
}
}
});
}
}
});
}
private static Session openActiveSession(Activity activity, boolean allowLoginUI, Session.StatusCallback callback) {
Session.Builder builder = new Builder(activity);
Session session = builder.build();
Session.OpenRequest openRequest = new OpenRequest(activity);
List<String> permission=new ArrayList<String>();
permission.add("user_birthday");
permission.add("user_likes");
permission.add("user_location");
permission.add("email");
if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI) {
openRequest.setPermissions(permission);
Session.setActiveSession(session);//This will take care of the null pointer
openRequest.setCallback(callback);//the callback
session.openForRead(openRequest);
return session;
}
return null;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(_mActivity, requestCode, resultCode, data);
}
当我尝试拨打session.isPermissionGranted("user_birthday")
时,会给false
我如何获得 user_birthday
的授权许可答案 0 :(得分:1)
您将获得null,因为您需要Facebook审核的APK才能获得用户的生日,如果您尝试使用开发者的Facebook帐户登录(已创建Facebook应用程序),您将获得生日,但对于一般公众访问,你必须提供APK审查到Facebook。
如果您有任何疑问,请与我们联系。
答案 1 :(得分:0)
对于生日和电子邮件地址,您无法在此呼叫中首先进入(登录身份验证)呼叫,您只能获得用户常规配置文件,只有少数几个参数。 如果您想获取出生日期/电子邮件/朋友列表,那么您必须使用特定权限进行单独的呼叫过帐身份验证。如需许可请通过以下链接 https://developers.facebook.com/docs/facebook-login/permissions