Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

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

Open
PawelJagus opened this issue Mar 9, 2016 · 15 comments

Comments

@PawelJagus
Copy link

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
Copy link

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
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link

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
Copy link
Author

@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
Copy link

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
Copy link

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
Copy link

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
Copy link
Author

@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
Copy link

@habuma is twitter integration dead?

@keyuls
Copy link

keyuls commented Jun 27, 2018

Is it fix or still the issue?

@AlexBondor
Copy link

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?

@heruan
Copy link

heruan commented Apr 18, 2019

This feature is definitely needed, but the project hasn't released new versions since a while. @habuma can you share some feedback on the status of 2.0.0, possibly with this feature included? Any ETA?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

8 participants