简体   繁体   中英

Twitter4j: Authentication credentials are missing error

import java.util.List;

import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.*;

public class Twitter_app {

    public static void main(String[] args) throws TwitterException {
        // TODO Auto-generated method stub
        try
        {
 ConfigurationBuilder cb= new ConfigurationBuilder();
  cb.setDebugEnabled(true)
  .setOAuthConsumerKey("XXX")
    .setOAuthConsumerSecret("XXXX")
    .setOAuth2AccessToken("XXXXX")
    .setOAuthAccessTokenSecret("XXXXXX")
    ;

    TwitterFactory tf= new TwitterFactory(cb.build()); //configurations
    Twitter twitter= tf.getInstance(); 
    List<Status> statuses = twitter.getHomeTimeline(); //get timeline
    System.out.println("Showing @" + twitter.getScreenName() + "'s home timeline."); //getting user's screen name
    for(Status status : statuses)
    {
        System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
    }
        }
 catch(TwitterException te) {
         te.printStackTrace();
         System.out.println("Failed to get timeline: " + te.getMessage());
         System.exit(-1);
    }

    }
}

But i get this the kwown error message "Authentication credentials are missing. See http://twitter4j.org/en/configuration.html for the detail." I am not able to find the error. Any help?

You used setOAuth 2 AccessToken, the html page only has setOAuthAccessToken. Maybe you want to remove the '2' and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM