1

Need to fetch twitter user profile data after successfully logging in using parse. Please refer below code :

ParseTwitterUtils.logIn(SignupActivity.this, new LogInCallback() {
        @Override
        public void done(ParseUser parseUser, ParseException e) {
            if (parseUser == null) {
                Log.d("MyApp", "Uh oh. The user cancelled the Twitter login.");
            } else if (parseUser.isNew()) {
                Log.d("MyApp", "User signed up and logged in through Twitter!");
            } else {
                Log.d("MyApp", "User logged in through Twitter!");
            }
        }
    });

I tried to get values from Parseuser object returned after login but it is showing null. Suggest what should I do after logging in.

Thanks

1 Answer 1

3

First off: Are you sure that you are logged in? To verify this, make sure that in your console there is the Log "User logged in through Twitter!", if so, you can add:

String twitter = ParseTwitterUtils.getTwitter().getScreenName(); Log.d(MainActivity.class.getSimpleName(), twitter + "");

under your else if and else block, or you can replace your code with this:

ParseTwitterUtils.logIn(SignupActivity.this, new LogInCallback() { @Override public void done(ParseUser parseUser, ParseException e) { if (parseUser == null) { Log.d("MyApp", "Uh oh. The user cancelled the Twitter login."); } else if (parseUser.isNew()) { Log.d("MyApp", "User signed up and logged in through Twitter!"); String twitter = ParseTwitterUtils.getTwitter().getScreenName(); Log.d(MainActivity.class.getSimpleName(), twitter + ""); } else { Log.d("MyApp", "User logged in through Twitter!"); String twitter = ParseTwitterUtils.getTwitter().getScreenName(); Log.d(MainActivity.class.getSimpleName(), twitter + ""); } } });

If your class is not "MainActivity", type it in the Log.d.

If you are having trouble singing in, you can also try this:

user = new ParseUser();
user.setUsername("Username");
user.setPassword("password");
user.setEmail("[email protected]");

user.signUpInBackground(new SignUpCallback() {
    public void done(ParseException e) {
        if (e == null) {
            // Hooray! Let them use the app now.
        } else {
            // Sign up didn't succeed. Look at the ParseException
            // to figure out what went wrong
        }
    }
});


if (!ParseTwitterUtils.isLinked(user)) {
    ParseTwitterUtils.link(user, this, new SaveCallback() {
        @Override
        public void done(ParseException ex) {
            if (ParseTwitterUtils.isLinked(user)) {
                Log.d("MyApp", "Woohoo, user logged in with Twitter!");

                String twitter = ParseTwitterUtils.getTwitter().getScreenName();
                Log.d(MainActivity.class.getSimpleName(), twitter + "");
            }
        }
    });
}

define "ParseUser user;" outside the onCreate method.

Sign up to request clarification or add additional context in comments.

2 Comments

@Agosttinelli thanks for explaining in detail. but I cannot fetch other details apart from getScreenName(). How can I fetch user profile_image,email,birthday,gender etc.
Well, here you can find the documentation for the class ParseTwitterUtils: parse.com/docs/android/api/com/parse/… But if you want profile_image, email etc etc... You have to use the Twitter REST API: dev.twitter.com/rest/public and make queries using OkHttp library for example, and get back data in a JSON format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.