New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getEmail of org.springframework.social.connect.UserProfile returns null even if additional permissions granted #97

Open
PawelJagus opened this Issue Mar 9, 2016 · 14 comments

Comments

Projects
None yet
7 participants
@PawelJagus

PawelJagus commented Mar 9, 2016

Hi, I have been granted an email request from a user of my app. I have activated "Request email addresses from users" in my Twitter app settings.

After this change the implementation of org.springframework.social.connect.UserProfile for Twitter still returns null when getEmail method is called.

@fieder

This comment has been minimized.

fieder commented Mar 18, 2016

+1

I'm having exactly the same problem.

Twitter exposes the email in the following way, optional parameter include_email
https://dev.twitter.com/rest/reference/get/account/verify_credentials

But TwitterProfile.java does not have email attribute and should add include_email parameter in the URL. Here's the line where the UserProfile is returned
return restTemplate.getForObject(buildUri("account/verify_credentials.json"), TwitterProfile.class);

@PawelJagus

This comment has been minimized.

PawelJagus commented Mar 19, 2016

I changed the source code by adding ?include_email=true and built a snapshot but it does not work anyway, the problem seems to be somewhere else.

@fieder

This comment has been minimized.

fieder commented Mar 19, 2016

I've managed to implement the workaround successfully by doing what you describe. I can now retrieve email that way. I've added email attribute to TwitterProfileWithEmail.class which I pass to getForObject. Email is populated. Bear in mind your app must be whitelisted by Twitter first. After that you checkbox email access permission in your app profile. Revoke permission from your user. Login back again, you will see explicit permission for email and after that restTemplate call it works in my case. Good luck!

@PawelJagus

This comment has been minimized.

PawelJagus commented Mar 20, 2016

Hi, the problem is that my app is whitelisted. I have revoked permission to my app from my user and then granted it once again upon signing up and still nothing...

This is how my app permissions look like.

@PawelJagus

This comment has been minimized.

PawelJagus commented Mar 20, 2016

I have solved it successfully. What had been missing was the following line in the TwitterAdapter class in the method fetchUserProfile. Nevertheless this is just a workaround and this feature should be enabled in the next version. Hardcoding the include_email=true does not seem like a good idea, there should be a possibility to use parameter forwarding by auth/twitter exactly like it is in Spring Social Facebook and Spring Social Google.

return new UserProfileBuilder().setName(profile.getName()).setUsername(profile.getScreenName()).setEmail(profile.getEmail()).build();
@RawSanj

This comment has been minimized.

RawSanj commented Mar 20, 2016

@fieder I have the required app permission but I am still not getting email.
I sent the this after making sure that User is logged in to twitter:
RestTemplate restTemplate = twitterTemplate.getRestTemplate();
String response = restTemplate.getForObject("https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true", String.class);
System.out.println(response);

Response doesn't contain email id:

{
  "id": 4538536787,
  "id_str": "4538536787",
  "name": "TestUsername",
  "screen_name": "TestUsername",
  "location": "",
  "description": "",
  "url": null,
  "entities": {
    "description": {
      "urls": [

      ]
    }
  },
  "protected": false,
  "followers_count": 0,
  "friends_count": 0,
  "listed_count": 0,
  "created_at": "Sat Dec 19 19:34:03 +0000 2015",
  "favourites_count": 0,
  "utc_offset": -25200,
  "time_zone": "Pacific Time (US & Canada)",
  "geo_enabled": false,
  "verified": false,
  "statuses_count": 0,
  "lang": "en",
  "contributors_enabled": false,
  "is_translator": false,
  "is_translation_enabled": false,
  "profile_background_color": "F5F8FA",
  "profile_background_image_url": null,
  "profile_background_image_url_https": null,
  "profile_background_tile": false,
  "profile_image_url": "http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_1_normal.png",
  "profile_image_url_https": "https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_1_normal.png",
  "profile_link_color": "2B7BB9",
  "profile_sidebar_border_color": "C0DEED",
  "profile_sidebar_fill_color": "DDEEF6",
  "profile_text_color": "333333",
  "profile_use_background_image": true,
  "has_extended_profile": false,
  "default_profile": true,
  "default_profile_image": true,
  "following": false,
  "follow_request_sent": false,
  "notifications": false
}

What is wrong here?
@PawelJagus @fieder can you guys share how did you get it working?

@PawelJagus

This comment has been minimized.

PawelJagus commented Mar 20, 2016

@RawSanj

I receive the email right after "notifications".

{
    ...
    "default_profile": true,
    "default_profile_image": true,
    "following": false,
    "follow_request_sent": false,
    "notifications": false,
    "email": "pawel.jagus@example.com"
}

Make sure that you are signing up with your user and not signing in with a user you have already been working with.

@fieder

This comment has been minimized.

fieder commented Mar 21, 2016

You also need to regenerate all tokens generated in Twitter. Revoke app permission from your user and try to login again to make sure the token generated includes that permission.

From my end what I did was
TwitterProfileWithEmail tpwe = rt.getForObject(URIBuilder.fromUri(API_URL_BASE + TWITTER_PATH).build(), TwitterProfileWithEmail.class); where TwitterProfileWithEmail is a copy of TwitterProfile but with an extra String attribute called email

Cheers.

@RawSanj

This comment has been minimized.

RawSanj commented Apr 17, 2016

Thanks @fieder. I regenerated the tokens generated in Twitter and it worked.
But I couldn't get it working the way you explained. So I converted the JSON returned from Twitter to POJO 😆.
My Sample Commit.

@MaveZ

This comment has been minimized.

MaveZ commented May 20, 2016

@PawelJagus Can you explain me how can I implement your solution to my application? I'm using spring-social too but I cannot modify TwitterAdapter since it is a class.

@PawelJagus

This comment has been minimized.

PawelJagus commented Jun 8, 2016

@MaveZ Sorry for not having answered earlier. I have had a lot to do lately. I will try to find some time to push my changes into GitHub, so you can see what I have changed. I modified the source code in the TwitterAdapter class in order to be able to get the email address from Twitter.

@Bessonov

This comment has been minimized.

Bessonov commented Mar 11, 2017

@habuma is twitter integration dead?

@keyuls

This comment has been minimized.

keyuls commented Jun 27, 2018

Is it fix or still the issue?

@AlexBondor

This comment has been minimized.

AlexBondor commented Jun 28, 2018

It is but.. is there an updated dependency pushed anywhere so I could fetch it instead of doing the changes locally and publishing to local m2 repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment