twitter4j xAuth authentication

2019-08-15 17:06发布

问题:

I'm trying to integrate xauth authentication using the twitter4j library

I've found multiple guides similar to http://www.hiteshagrawal.com/java/twitter-xauth-permission-using-java that all indicate i should have the line:

Twitter twitter = new TwitterFactory().getInstance(username, password);

But this gives me an error, because the getInstance() method doesn't allow the parameter of two strings.

Did the twitter4j library change, or am I doing something wrong?

回答1:

Twitter deprecated Basic authentication and as of Twitter4J 2.2.0, you need to use Twitter#getOAuthAccessToken(id,password) to get the access token. http://twitter4j.org/en/versions.html#migration21x-22x