簡體   English   中英

無法使用Facebook SDK獲取用戶電子郵件和生日

[英]Unable to fetch user email and birthday using Facebook SDK

我正在編寫一個程序,試圖在該程序中獲取user's basic information例如: IdNameEmailBirthdayLocale等。

我已成功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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM