简体   繁体   中英

How to authenticate users on server using facebook on android app

I am building an Android app that works with a server. The servers needs to do all of the work. I want to have my users creates accounts and connect using facebook.

I don't know what information I need to keep in the database about the user to be able to authenticate him if he changes phone, reinstall the app or anything that would modify his facebook token.

I don't knoz if i'm clear enough I'm a bit confused by facebook auth :/

This is how you can get the id of the facebook-user :

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this);
    setContentView(R.layout.activity_main);


    callbackManager = CallbackManager.Factory.create();

    login = (LoginButton) findViewById(R.id.btn_login);
    login.setReadPermissions("email", "public_profile");
    login.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {

                    String id = object.getString("id");
                    // some database stuff here
                    // ...
                }
            });
            request.executeAsync();
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {
            Log.d("ERROR", error.toString());
            Toast.makeText(MainActivity.this, "Couldn't login, pleasy try again!", Toast.LENGTH_SHORT).show();
        }
    });

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM