我正在使用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

最佳答案

尝试使用以下配置:

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);

我希望这有帮助。

佐兰

10-04 19:07