OAuth with twitter4j and getting email

restapi
oauth
twitter4j

#1

Hi guys!

I’d like to auth our users with twitter using twitter4j Java driver, then get their email and name. I successfully got request and access token and then I tried to access to user’s data like this:

User user=TwitterFactory.getSingleton().verifyCredentials();

user contains everything I need but email. It has the field email, but it’s null.

More infos:

  • I sent a request to twitter to allow my app to request user’s email address. They gave me an answer that it doest not needed anymore, just check a checkbox in my app’s admin and done. It’s done.
  • That time, I thought maybe something is wrong with twitter4j, so I tried to query data via OAuth Tool which I found in the app’s admin. Unfortunately when I run the generated curl command in my terminal I get HTTP 404
  • I found a similar topic, I think, the guy has the same problem: Email return null using twitter4j permissions having been set

I feel lost now. What do you recommend?


#2

First of all, which version of Twitter4J are you using?

There are a few reasons why the value could by null/empty - if you didn’t re-authenticate after adding the request email permission, the user token will retain the old permissions. You may also choose to regenerate you keys but that should not be necessary. Also, if the email address is not verified (i.e. the user has never clicked through the “confirm email address” link in the welcome email), then it will not be shared in the user object. Finally, some users that have signed up through a phone-based flow may not have added an email to their accounts.


#3

Hi!

Thank you for your answer!
I’m using the latest twitter4J (see below). When I test, I always generate a new request token, so I think, that is not a problem.
However, your other tips seem interesting, I’ll try these out and get back with the result.

<repositories>
    <repository>
        <id>twitter4j.org</id>
        <name>twitter4j.org Repository</name>
        <url>http://twitter4j.org/maven2</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
...
<dependency>
  <groupId>org.twitter4j</groupId>
  <artifactId>twitter4j-core</artifactId>
  <version>[4.0,)</version>
</dependency>

#4

Hi. It works now! Had to confirm the email address and enable in the config for twitter4j like:

includeEmail=true

#5

Ah, great news! Thanks for sharing the solution here too.


#6