Android 无法使用Facebook SDK获取用户电子邮件和生日
我正在编写一个程序,试图获取用户的基本信息,比如:Android 无法使用Facebook SDK获取用户电子邮件和生日,android,facebook,facebook-sdk-3.0,Android,Facebook,Facebook Sdk 3.0,我正在编写一个程序,试图获取用户的基本信息,比如:Id、Name、Email、birth、Locale等等 我成功地获取了这些详细信息:Id、Name、Locale 但是在获取时获取null:电子邮件和生日 请检查下面的我的代码: private static final List<String> PERMISSIONS = Arrays.asList("public_profile", "email", "user_location", "user_birthday");
Id
、Name
、Email
、birth
、Locale
等等
我成功地获取了这些详细信息:Id、Name、Locale
但是在获取时获取null
:电子邮件和生日
请检查下面的我的代码:
private static final List<String> PERMISSIONS = Arrays.asList("public_profile", "email", "user_location", "user_birthday");
String get_id, get_name, get_gender, get_email, get_birthday, get_locale, get_location;
............................................................
loginBtn = (LoginButton) findViewById(R.id.authButton);
loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
userName.setText("Hello, " + user.getName());
userInformation.setText(buildUserInfoDisplay(user));
} else {
userName.setText("You are not Logged In");
userInformation.setText("");
}
}
});
}
private String buildUserInfoDisplay(GraphUser user) {
StringBuilder userInfo = new StringBuilder("");
userInfo.append(String.format("First Name: %s\n\n", user.getFirstName()));
userInfo.append(String.format("Last Name: %s\n\n", user.getLastName()));
userInfo.append(String.format("Birthday: %s\n\n", user.getBirthday()));
userInfo.append(String.format("Email: %s\n\n", user.getProperty("email")));
userInfo.append(String.format("Locale: %s\n\n", user.getProperty("locale")));
return userInfo.toString();
}
private static final List PERMISSIONS=Arrays.asList(“公共配置文件”、“电子邮件”、“用户位置”、“用户生日”);
字符串get_id、get_name、get_gender、get_email、get_birth、get_locale、get_location;
............................................................
loginBtn=(LoginButton)findViewById(R.id.authButton);
loginBtn.setUserInfoChangedCallback(新的UserInfoChangedCallback(){
@凌驾
已获取公用void onUserInfo(GraphUser用户){
如果(用户!=null){
userName.setText(“Hello,”+user.getName());
setText(buildUserInfoDisplay(user));
}否则{
userName.setText(“您未登录”);
userInformation.setText(“”);
}
}
});
}
私有字符串buildUserInfoDisplay(GraphUser用户){
StringBuilder userInfo=新的StringBuilder(“”);
userInfo.append(String.format(“名字:%s\n\n”,user.getFirstName());
userInfo.append(String.format(“姓氏:%s\n\n”,user.getLastName());
userInfo.append(String.format(“生日:%s\n\n”,user.getbirth());
userInfo.append(String.format(“电子邮件:%s\n\n”,user.getProperty(“电子邮件”));
userInfo.append(String.format(“区域设置:%s\n\n”,user.getProperty(“区域设置”));
返回userInfo.toString();
}
现在我得到的是
:
名字:Kim
姓氏:DSouza
生日:null
电子邮件:null
区域设置:
en_US
我发现的问题很小,只需在活动中使用此选项即可:
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
onSessionStateChange(session, state, exception);
if (session.isOpened()) {
Log.i(TAG,"Access Token"+ session.getAccessToken());
Request.newMeRequest(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,Response response) {
}
});
您可以使用like获得电子邮件id、生日 电邮:
String email = user.getProperty("email").toString();
生日:
String birth =user.getBirthday()
你对所有这些字段有什么要求?你需要特别要求电子邮件和生日,如果你想要这些字段+1尝试引用我解决了我的问题:)这不起作用,无法使用此字段获取电子邮件