I'm using twitter4j 4.0.3 core
I have this code:
public final class TwitterUtil {
private RequestToken requestToken = null;
private TwitterFactory twitterFactory = null;
private Twitter twitter;
private TwitterUtil()
{
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(ConstantValues.TWITTER_CONSUMER_KEY);
configurationBuilder.setOAuthConsumerSecret(ConstantValues.TWITTER_CONSUMER_SECRET);
configurationBuilder.setUseSSL(true);
Configuration configuration = configurationBuilder.build();
twitterFactory = new TwitterFactory(configuration);
twitter = twitterFactory.getInstance();
AccessToken accessToken = new AccessToken(ConstantValues.PREFERENCE_TWITTER_OAUTH_TOKEN,ConstantValues.PREFERENCE_TWITTER_OAUTH_TOKEN_SECRET);
twitter.setOAuthAccessToken(accessToken);
}
public TwitterFactory getTwitterFactory()
{
return twitterFactory;
}
public void setTwitterFactory(AccessToken accessToken)
{
twitter = twitterFactory.getInstance(accessToken);
}
public Twitter getTwitter()
{
return twitter;
}
public RequestToken getRequestToken() {
if (requestToken == null) {
try {
requestToken = twitterFactory.getInstance().getOAuthRequestToken(ConstantValues.TWITTER_CALLBACK_URL);
} catch (TwitterException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
return requestToken;
}
static TwitterUtil instance = new TwitterUtil();
public static TwitterUtil getInstance() {
return instance;
}
public void reset() {
instance = new TwitterUtil();
}
}
But it always throws this error on setUseSSL
:
cannot resolve method - setUsessl(boolean)
What it may be? Maybe a version issue?
Also, on my module build.gradle:
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
compile 'com.android.support:support-v4:18.0.0'
compile 'org.twitter4j:twitter4j:4.0.3'
compile 'org.twitter4j:twitter4j-appengine:4.0.3'
compile 'org.twitter4j:twitter4j-core:4.0.3'
compile files('libs/twitter4j-core-3.0.3.jar')
}
I placed a file unto libs folder, trying to add it from here, no matter if I delete the other versions, the jar seems not to be working, or added to the project, also I can't see my project root 'libs' folder from IDE.
What am I doing wrong?
Thanks in advance1
Try to use the following configuration:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthAuthenticationURL("https://api.twitter.com/oauth/request_token");
cb.setOAuthAccessTokenURL("https://api.twitter.com/oauth/access_token");
cb.setOAuthAuthorizationURL("https://api.twitter.com/oauth/authorize");
cb.setOAuthRequestTokenURL("https://api.twitter.com/oauth/request_token");
cb.setRestBaseURL("https://api.twitter.com/1.1/");
cb.setOAuthConsumerKey(consumerKey);
cb.setOAuthConsumerSecret(consumerSecret);
You should not set cb.setUseSSL(true);
I hope this helps.
Zoran