I have integrated latest Facebook android sdk 4.0. In SDK 3.0+ user's email address is retreived using user.getProperty("email") after successful login. I am looking for corresponding command in Facebook Android sdk 4.0 Reference Links:
http://ift.tt/1NJOQqX http://ift.tt/1M0W38F
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
callbackManager = CallbackManager.Factory.create();
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("email", "user_likes", "user_friends");
loginButton.setFragment(this);
setFacebookLoginText(loginButton);
// Other app specific specialization
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse graphResponse) {
//Need User email address after login success.
}
}).executeAsync();
}
@Override
public void onCancel() {
Toast.makeText(getActivity(), "fail", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(getActivity(), "error", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_facebook_login, container, false);
return view;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
Aucun commentaire:
Enregistrer un commentaire