[英]Unable to fetch Friendlist Birthday Facebook 3.0 android
[英]Unable to fetch user email and birthday using Facebook SDK
我正在編寫一個程序,試圖在該程序中獲取user's basic information
例如: Id
, Name
, Email
, Birthday
, Locale
等。
我已成功fetched
以下詳細信息:ID,名稱,語言環境
但是getting 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();
}
現在我getting
:
名: 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) {
}
});
您可以使用類似的方法獲取電子郵件ID,生日
對於電子郵件:
String email = user.getProperty("email").toString();
生日:
String birth =user.getBirthday()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.