How to link Google + signed in users on Parse backend on Android?

后端 未结 5 707
名媛妹妹
名媛妹妹 2020-12-14 07:58

I\'ve been using Parse for 3 months in my android app. Now I want to add email login and social sign ons (Facebook and Google+) in the app. I have successfully added email a

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 08:39

    void createNewGPlusUser(final String email, String name) {
            final ParseUser user = new ParseUser();
            user.setUsername(email);
            user.setPassword("my pass");
            user.put("any other variable in User class", "value");
            user.setEmail(email);
            user.put("name", name);
            signInParseUser(user, email);
        }
    
    void signInParseUser(final ParseUser user, final String email) {
    
            user.signUpInBackground(new SignUpCallback() {
                public void done(ParseException e) {
                    if (e == null) {
                        Log.d("TAG", "Created user");
                        // Hooray! Let them use the app now.
                        login(email);
                    } else {
                        Log.d("TAG", "Failed Creating user");
                        e.printStackTrace();
                        // Sign up didn't succeed. Look at the ParseException
                        // to figure out what went wrong
                    }
                }
            });
        }
    
    void login(final String email) {
            ParseUser.logInInBackground(email, "my pass", new LogInCallback() {
                public void done(ParseUser user, ParseException e) {
                    if (user != null) {
                        // Hooray! The user is logged in.
                        Log.d("TAG", "Login successful");
                                        } else {
                                            // Signup failed. Look at the ParseException to see what happened.
                    }
                }
            });
        }
    

提交回复
热议问题