Get user email from Facebook SDK android [closed]

本秂侑毒 提交于 2019-12-13 02:09:26

问题


I am just starting out with the Facebook SDK, I currently have an app that has its own login system, the user enters their email and password and then the app checks a mysql database to find the user. If the user is their it returns the user info and logs them into the app.

What I am trying to do is allow the user to just press a Facebook button and have the Facebook SDK return the users email linked to their Facebook account. Then I can search my database for that email and log the user in or create an account for them if their is no account with that email.

I have everything set up apart from having the Facebook SDK actually return the email for the user. I am not sure where to start with this and could really use some help!


回答1:


You have two options to get the email of the Facebook user:

Option 1: Use Facebook SDK

  1. Implement Facebook Login with email permission
  2. Get the user data by using Request.newMeRequest(). This is explained here: Personalize

Oprion 2: Use Simple Facebook SDK library

The library: https://github.com/sromku/android-simple-facebook

  1. Set email permission by using Permissions.EMAIL
  2. Then, login

    mSimpleFacebook.login(MainActivity.this);
    
  3. And then, get the profile with the email

    mSimpleFacebook.getProfile(new OnProfileRequestAdapter()
    {
        @Override
        public void onComplete(Profile profile)
        {
            String id = profile.getId();
            String firstName = profile.getFirstName();
            String email = profile.getEmail();
            // ... and many more properties of profile ...
        }
    });
    


来源:https://stackoverflow.com/questions/18701954/get-user-email-from-facebook-sdk-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!