0

First time using the twtter4j library and I keep getting the error "consumer key/secret pair already set"

here's my code

import twitter4j.conf.*;
import twitter4j.*;
import twitter4j.auth.*;
import twitter4j.api.*; 

static String OAuthConsumerKey = "....";
static String OAuthConsumerSecret = "...";
static String AccessToken = "....";
static String AccessTokenSecret = "....";

TwitterStream twitter = new TwitterStreamFactory().getInstance();



void setup() {

  connectTwitter();
  twitter.addListener(listener);
  twitter.sample(); // grabs random tweet

}

void draw() {
}


// initial connection 
void connectTwitter() {
  twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
  AccessToken accessToken = loadAccessToken();
  twitter.setOAuthAccessToken(accessToken);
}

// Loading up the access token

private static AccessToken loadAccessToken() {
  return new AccessToken(AccessToken, AccessTokenSecret);
}

// This listens for new tweet

StatusListener listener = new StatusListener() {
  public void onStatus(Status status) {
    Boolean bool = true;
    while (bool) {
      println("@" + status.getUser().getScreenName() + " - " + status.getText());
      bool = false;
    }
  }
  public void onStallWarning(StallWarning stallwarning) {
  }
  public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
  }
  public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
  }
  public void onScrubGeo(long userId, long upToStatusId) {
    System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
  }
  public void onException(Exception ex) {
    ex.printStackTrace();
  }
}; 

the line "twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);" is highlighted.

any help with this would be greatly appreciated. Been stuck for ages.

  • 2
    Possible duplicate of [Twitter integration:consumer key/secret pair already set](http://stackoverflow.com/questions/11505862/twitter-integrationconsumer-key-secret-pair-already-set) – Kevin Workman Dec 07 '15 at 16:31

1 Answers1

-1

I faced this problem as well when I was trying to retrieve my own tweets. Make sure that you omit the "twitter4j-examples.jar" from the twitter4j download (make sure it is the latest version). Extract the files and import the other jar files and it should work. For some reason the examples jar file from the download sets consumer key and secret that is completely different from the one the twitter application gives you. Hope this helps

jubilantdollop
  • 223
  • 3
  • 11