lundi 30 mars 2015

Android Facebook 4.0 SDK How to get Email, Date of Birth and gender of User

I am using the following code. I want the user Date Of Birth, Email and Gender of the User. Please help. How to retrieve those data?


This is my onViewCreated() inside the Fragment.



@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

// Setup TextView.
mTextDetails = (TextView) view.findViewById(R.id.text_details);

// Set up Login Button.
LoginButton mButtonLogin = (LoginButton) view.findViewById(R.id.login_button);
// setFragment only if you are using it inside a Fragment.
mButtonLogin.setFragment(this);
mButtonLogin.setReadPermissions("user_friends");
mButtonLogin.setReadPermissions("public_profile");
mButtonLogin.setReadPermissions("email");
mButtonLogin.setReadPermissions("user_birthday");

// Register a callback method when Login Button is Clicked.
mButtonLogin.registerCallback(mCallbackManager, mFacebookCallback);

}


This is my Callback Method.



private FacebookCallback<LoginResult> mFacebookCallback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d("Shreks Fragment", "onSuccess");


Profile profile = Profile.getCurrentProfile();
Log.d("Shreks Fragment onSuccess", "" +profile);

// Get User Name
mTextDetails.setText(profile.getName() + "");

}


@Override
public void onCancel() {
Log.d("Shreks Fragmnt", "onCancel");
}

@Override
public void onError(FacebookException e) {
Log.d("Shreks Fragment", "onError " + e);
}
};

Aucun commentaire:

Enregistrer un commentaire