How to get an email address from users on Twitter4J?

I'm glad that now we can get the email address from users now using "Twitter4J".

But, my problem is that I canโ€™t use a function that brings email from users. My server (based on Spring) used Twitter4J with a "maven dependency". I use the method described on the Twitter4J main page ( http://twitter4j.org/en/index.html ):

<dependencies> <dependency> <groupId>org.twitter4j</groupId> <artifactId>twitter4j-core</artifactId> <version>[4.0,)</version> </dependency> ... </dependencies> 

However, this method cannot bring your latest feature, which brings an email even with SNAPSHOT Build Version '. I think this method cannot bring the latest version of Twitter4J, which was recently uploaded to github.

How can I use the getEmail() function using Twitter4J in my application?

Any help is greatly appreciated, thanks in advance.

+5
source share
1 answer

Firstly, you need to get your application in the white list from the documentation :

Requesting users email address requires your application to be included in the white list of Twitter.

If you get permission, you need to configure ConfigurationBuilder wtih setIncludeEmailEnabled(true)

 ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(cKey); builder.setOAuthConsumerSecret(cSecret); builder.setOAuthAccessToken(accessToken.getToken()); builder.setOAuthAccessTokenSecret(accessToken.getTokenSecret()); builder.setIncludeEmailEnabled(true); 

And then you can receive user mail after checking credentials

 User user = twitter.verifyCredentials(); System.out.print(user.getEmail()); 

As Patrick Denny points out, this method works on October 4, 2016 on Twitter4j 4.0.5

So, if you have an older version and need to receive an email, please update

+5
source

Source: https://habr.com/ru/post/1243734/


All Articles