2015-09-09 68 views
1

我想獲得一些Facebook用戶的個人資料信息,如姓名,電子郵件,生日和地點。我無法獲得用戶的生日。無法獲取FB用戶生日,android?

callbackManager = CallbackManager.Factory.create(); 
    loginManager=LoginManager.getInstance(); 
    loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) { 
      // App code 
      accessToken = AccessToken.getCurrentAccessToken(); 
      getProfileInformationFacebook(accessToken); 
      Log.e("login res", loginResult.toString()); 
     } 

     @Override 
     public void onCancel() { 
      // App code 
     } 

     @Override 
     public void onError(FacebookException exception) { 
      // App code 
     } 
    }); 

讀取權限:

loginManager.logInWithReadPermissions(this, 
       Arrays.asList("user_about_me", "user_birthday", "user_location", "email")); 

圖形API請求:

public void getProfileInformationFacebook(AccessToken accToken) { 
    GraphRequest request = GraphRequest.newMeRequest(
      accToken, 
      new GraphRequest.GraphJSONObjectCallback() { 
       @Override 
       public void onCompleted(
         JSONObject object, 
         GraphResponse response) { 
        Log.e("object", object.toString()); 
        String fbId = null; 
        String fbBirthday = null; 
        String fbLocation = null; 
        String fbEmail = null; 
        String fbName = null; 

        try { 
         fbId = object.getString("id"); 
         fbEmail = object.getString("email"); 
         fbName = object.getString("name"); 
         fbBirthday = object.getString("birthday"); 
         JSONObject jsonObject = object.getJSONObject("location"); 
         fbLocation = jsonObject.getString("name"); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
      }); 
    Bundle parameters = new Bundle(); 
    parameters.putString("fields", "id,name,email,location,birthday"); 
    request.setParameters(parameters); 
    request.executeAsync(); 

圖形API響應:

{"id":"10153618779823958","email":"[email protected]","name":"Wishy Gupta"} 

是這裏缺少點什麼?

回答