简体   繁体   English

如何从“Twitter4J”中获取用户的电子邮件地址?

[英]How do I get an email address from users in 'Twitter4J'?

I'm glad that now we can get an email address from users now with 'Twitter4J'. 我很高兴现在我们可以通过'Twitter4J'获得用户的电子邮件地址。

But, my problem is that I can't use the function which is bring an email from users. 但是,我的问题是我无法使用带来用户电子邮件的功能。 My server (based on Spring) had been using Twitter4J with 'maven dependency'. 我的服务器(基于Spring)一直在使用Twitter4J和'maven依赖'。 I'm using the way that described in Twitter4J's homepage( http://twitter4j.org/en/index.html ): 我正在使用Twitter4J主页( http://twitter4j.org/en/index.html )中描述的方式:

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

However, this way can not bring your latest function which is bring an email even use SNAPSHOT Build Version'. 但是,这种方式无法带来你带来电子邮件的最新功能甚至使用SNAPSHOT Build Version'。 I think this way can not bring the latest version of Twitter4J which was upload recently in github. 我认为这种方式无法带来最近在github中上传的Twitter4J的最新版本。

How can I use getEmail() function using Twitter4J in my application? 如何在我的应用程序中使用Twitter4J使用getEmail()函数?

Any help is much appreciated, thanks in advance. 非常感谢任何帮助,在此先感谢。

First, you need to get your application whitelisted, from the documentation : 首先,您需要从文档中将您的应用程序列入白名单:

Requesting a user's email address requires your application to be whitelisted by Twitter. 请求用户的电子邮件地址要求您的应用程序被Twitter列入白名单。

If you get the permission You need to set up the ConfigurationBuilder wtih setIncludeEmailEnabled(true) 如果您获得了权限您需要使用setIncludeEmailEnabled(true)设置ConfigurationBuilder

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 get the user mail after verifying the credentials 然后,您可以在验证凭据后获取用户邮件

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

As Patrick Denny points out, this method is live at Oct 4th 2016 in Twitter4j 4.0.5 正如Patrick Denny指出的那样, 这种方法将于2016年10月4日在Twitter4j 4.0.5上发布

So, if you have a older version and need to get the email, please upgrade 因此,如果您有旧版本并需要收到电子邮件,请升级

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM