我使用twitter4j 4.0.3核心
我有这段代码:
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();
}
}
但它始终会在setUseSSL
上抛出此错误:
cannot resolve method - setUsessl(boolean)
它可能是什么?也许版本问题?
另外,在我的模块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')
}
我把一个文件放到libs文件夹中,尝试从这里添加它,不管我是否删除了其他版本,jar似乎没有工作,或者添加到项目中,我也看不到我的项目根' libs'来自IDE的文件夹。
我做错了什么?
先谢谢1
答案 0 :(得分:1)
尝试使用以下配置:
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);
你不应该设置 cb.setUseSSL(true);
我希望这会有所帮助。
卓然