Twitter4j authentication credentials are missing

后端 未结 2 1402
夕颜
夕颜 2020-12-19 05:44

I would like to make a tweet with Twitter4j in my Android app. Here is my code:

 //TWITTER SHARE.
@Click (R.id. img_btn_twitter)
@Background
public void twit         


        
2条回答
  •  臣服心动
    2020-12-19 06:13

    Problem is following lines.

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = new TwitterFactory().getInstance();
    

    You are passing the configuration to one TwitterFactory instance and using another TwitterFactory instance to get the Twitter instance.

    Hence, You are getting java.lang.IllegalStateException: Authentication credentials are missing

    I suggest you to modify your code as follows:

        //Twitter Conf.
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(CONSUMER_KEY)
                .setOAuthConsumerSecret(CONSUMER_SECRET)
                .setOAuthAccessToken(ACCESS_KEY)
                .setOAuthAccessTokenSecret(ACCESS_SECRET);
    
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
    

    And use this twitter instance. It will work.

提交回复
热议问题