1

I am trying to use Parse.com on my Android Application to authenticate my users with Twitter.

Basically, I have a 'Register with Twitter' button. When the user presses this, the Twitter dialog opens, and he signs up. Here is the onClick() function for the Register With Twitter button:

public void registerTwitter(View view)
{
    ParseTwitterUtils.logIn(this, new LogInCallback() {
          @Override
          public void done(ParseUser user, ParseException err) {
            if (user == null) {
                               //do something else, User quit the dialog
            } 
            else if (user.isNew()) 
            {
                Intent i=new Intent(getApplicationContext(),Welcome.class);
                startActivity(i);
            } 
            else 
            {
                //User already exists, do something else
            }
          }
        });
}

Here, the code is working, and there is a ParseUser being created in the back as intended. However, the problem is: how do I get the other public data from the Twitter API to add to my ParseUser object? Like First Name, Last Name, Image, Email etc?

All I get at the backend is a number in the 'Username' field, and the authData object from Twitter

Any help would be appreciated! Thank you

2
  • What error are you getting in logcat just after it crashes? Logcat should always be your starting point for trying to diagnose a run-time error. In fact, if you read the stack of errors and just try to understand it, you'll probably be able to fix the error yourself 90% of the time by going to the line number the log points to into the file names that sound familiar to you because they're part of your project. As to the rest of your question, I can't really answer it since I'm not familiar enough with parse.com Commented Apr 20, 2014 at 20:00
  • Actually, I was able to fix the crash. The main problem is getting the data from the Twitter API Commented Apr 20, 2014 at 20:23

1 Answer 1

2

TwitterInfo twitterInfo = null;
		Twitter twitter = ParseTwitterUtils.getTwitter();
		String twitterUrl = "https://api.twitter.com/1.1/users/show.json?user_id=" + twitter.getUserId();

		HttpUriRequest request = new HttpGet(twitterUrl);
		twitter.signRequest(request);

		HttpClient client = new DefaultHttpClient();

		try
		{
			HttpResponse response = client.execute(request);
			BufferedReader input = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

			String result = input.readLine();
			Log.d(TAG, "getTwitterInfo: result=" + result);

			JSONObject JsonResponse = new JSONObject(result);

			String profileImageUrl = JsonResponse.getString("profile_image_url");
			String fullName = JsonResponse.getString("name");

			twitterInfo = new TwitterInfo(fullName, profileImageUrl);

			return twitterInfo;

		}
		catch(ClientProtocolException e)
		{
			throw new CamoPhotoException(e.getMessage());
		}
		catch(IOException e)
		{
			throw new CamoPhotoException(e.getMessage());

		}
		catch(JSONException e)
		{
			throw new CamoPhotoException(e.getMessage());

		}

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

Comments

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.