开发者

Cannot construct AccessToken with twitter4j

I've used the com.sugree.twitter technique to obtain the twitter access token and the access key. Now. I want to pass these into the twitter4j library. But, I am getting an e开发者_运维百科rror on this line as follows:

twitter4j.auth.AccessToken accessToken = new twitter4j.auth.AccessToken(twitter.getAccessToken(),twitter.getSecretToken());

06-21 18:43:08.140: ERROR/AndroidRuntime(1293): java.lang.IllegalStateException: Consumer key and Consumer secret not supplied.


Solution:

ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setDebugEnabled(true)
              .setOAuthConsumerKey(twitterKey)
              .setOAuthConsumerSecret(twitterSecret)
              .setOAuthAccessToken(twitter.getAccessToken())
              .setOAuthAccessTokenSecret(twitter.getSecretToken());
            TwitterFactory tf = new TwitterFactory(cb.build());
            twitter4j.Twitter t4jTwitter = tf.getInstance();


You can specify consumer key/secret in twitter4j.properties. http://twitter4j.org/en/configuration.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜