Java Code Examples for twitter4j.conf.ConfigurationBuilder

The following are top voted examples for showing how to use twitter4j.conf.ConfigurationBuilder. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: TwitterOAuthActivity.java   Source Code and License 8 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // setup twitter client
    mTwitter = new TwitterFactory(new ConfigurationBuilder()
            .setOAuthConsumerKey(getResources().getString(R.string.twitter_consumer_key))
            .setOAuthConsumerSecret(getResources().getString(R.string.twitter_consumer_secret))
            .build()).getInstance();

    // setup twitter webview
    mTwitterView = new WebView(this);
    mTwitterView.getSettings().setJavaScriptEnabled(true);

    // initialize view
    setContentView(mTwitterView);

    // start the web view
    loginToTwitter();
}
 
Example 2
Project: jcertif-android-2013   File: LoginFragment.java   Source Code and License 7 votes vote down vote up
private void loginToTwitter() {
	// Check if already logged in

	ConfigurationBuilder builder = new ConfigurationBuilder();
	builder.setOAuthConsumerKey(Config.TWITTER_CONSUMER_KEY);
	builder.setOAuthConsumerSecret(Config.TWITTER_CONSUMER_SECRET);
	Configuration configuration = builder.build();

	TwitterFactory factory = new TwitterFactory(configuration);
	twitter = factory.getInstance();

	try {
		requestToken = twitter.getOAuthRequestToken(Config.TWITTER_CALLBACK_URL);
		this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
	} catch (TwitterException e) {
		e.printStackTrace();
	}
}
 
Example 3
Project: camel-twitter-stream   File: TwitterSourceConfiguration.java   Source Code and License 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public TwitterFactory twitterFactory() {
	if (this.properties.getConsumerKey() == null
			|| this.properties.getConsumerSecret() == null
			|| this.properties.getAccessToken() == null
			|| this.properties.getAccessTokenSecret() == null) {
		throw new RuntimeException(
				"Twitter properties not configured properly. Please check twitter.* properties settings in configuration file.");
	}

	ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
	configurationBuilder.setDebugEnabled(false)
			.setOAuthConsumerKey(properties.getConsumerKey())
			.setOAuthConsumerSecret(properties.getConsumerSecret())
			.setOAuthAccessToken(properties.getAccessToken())
			.setOAuthAccessTokenSecret(properties.getAccessTokenSecret());
	return new TwitterFactory(configurationBuilder.build());
}
 
Example 4
Project: tweet-analysis   File: TwitterFeed.java   Source Code and License 6 votes vote down vote up
private Twitter getTwitter() {
    TwitterCredentials creds = readCredentials();
    if (creds.getConsumerKey() == null) {
        throw new RuntimeException("Incorrect Twitter client configuration: Consumer key is null");
    }
    if (creds.getConsumerSecret() == null) {
        throw new RuntimeException("Incorrect Twitter client configuration: Consumer secret is null");
    }
    if (creds.getAccessSecret() == null) {
        throw new RuntimeException("Incorrect Twitter client configuration: Access secret is null");
    }
    if (creds.getAccessToken() == null) {
        throw new RuntimeException("Incorrect Twitter client configuration: Access token is null");
    }
    ConfigurationBuilder twitterConfig = new ConfigurationBuilder();
    twitterConfig.setOAuthConsumerKey(creds.getConsumerKey());
    twitterConfig.setOAuthConsumerSecret(creds.getConsumerSecret());
    twitterConfig.setOAuthAccessToken(creds.getAccessToken());
    twitterConfig.setOAuthAccessTokenSecret(creds.getAccessSecret());
    twitterConfig.setJSONStoreEnabled(true);
    return new TwitterFactory(twitterConfig.build()).getInstance();
}
 
Example 5
Project: syndesis-qe   File: TwSfValidationSteps.java   Source Code and License 6 votes vote down vote up
public TwSfValidationSteps() {

		accountsDirectory = AccountsDirectory.getInstance();
		final Account twitterTalky = accountsDirectory.getAccount(RestConstants.getInstance().getSYNDESIS_TALKY_ACCOUNT()).get();
		//twitter
		final TwitterFactory factory = new TwitterFactory(new ConfigurationBuilder()
				.setOAuthConsumerKey(twitterTalky.getProperty("consumerKey"))
				.setOAuthConsumerSecret(twitterTalky.getProperty("consumerSecret"))
				.setOAuthAccessToken(twitterTalky.getProperty("accessToken"))
				.setOAuthAccessTokenSecret(twitterTalky.getProperty("accessTokenSecret"))
				.build());
		twitter = factory.getInstance();
		// salesforce
		final Account salesforceAccount = accountsDirectory.getAccount("salesforce").get();
		salesforce = new ForceApi(new ApiConfig()
				.setClientId(salesforceAccount.getProperty("clientId"))
				.setClientSecret(salesforceAccount.getProperty("clientSecret"))
				.setUsername(salesforceAccount.getProperty("userName"))
				.setPassword(salesforceAccount.getProperty("password"))
				.setForceURL(salesforceAccount.getProperty("loginUrl")));
	}
 
Example 6
Project: Babler   File: TwitterJobManagerUser.java   Source Code and License 6 votes vote down vote up
public TwitterJobManagerUser()
{
    languageDetector = new LanguageDetector();

    for(int i =0; i< twitKey.length; i++)
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(twitKey[i].getConsumer())
                .setOAuthConsumerSecret(twitKey[i].getSecret())
                .setOAuthAccessToken(twitKey[i].getAccess())
                .setOAuthAccessTokenSecret(twitKey[i].getToken_secret());

        TwitterFactory tf = new TwitterFactory(cb.build());
        keys[i] = tf.getInstance();

    }
}
 
Example 7
Project: Babler   File: TwitterCodeSwitchSJobManager.java   Source Code and License 6 votes vote down vote up
public TwitterCodeSwitchSJobManager()
{
    languageDetector = new LanguageDetector();

    for(int i =0; i< twitKey.length; i++)
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(twitKey[i].getConsumer())
                .setOAuthConsumerSecret(twitKey[i].getSecret())
                .setOAuthAccessToken(twitKey[i].getAccess())
                .setOAuthAccessTokenSecret(twitKey[i].getToken_secret());

        TwitterFactory tf = new TwitterFactory(cb.build());
        keys[i] = tf.getInstance();
    }
}
 
Example 8
Project: Babler   File: TwitterJobManager.java   Source Code and License 6 votes vote down vote up
public TwitterJobManager()
{

    languageDetector = new LanguageDetector();

    for(int i =0; i< twitKey.length; i++)
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(twitKey[i].getConsumer())
                .setOAuthConsumerSecret(twitKey[i].getSecret())
                .setOAuthAccessToken(twitKey[i].getAccess())
                .setOAuthAccessTokenSecret(twitKey[i].getToken_secret());

        TwitterFactory tf = new TwitterFactory(cb.build());
        keys[i] = tf.getInstance();

    }
}
 
Example 9
Project: Babler   File: TwitterSentimentJobManager.java   Source Code and License 6 votes vote down vote up
public TwitterSentimentJobManager()
{
    languageDetector = new LanguageDetector();

    for(int i =0; i< twitKey.length; i++)
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(twitKey[i].getConsumer())
                .setOAuthConsumerSecret(twitKey[i].getSecret())
                .setOAuthAccessToken(twitKey[i].getAccess())
                .setOAuthAccessTokenSecret(twitKey[i].getToken_secret());

        TwitterFactory tf = new TwitterFactory(cb.build());
        keys[i] = tf.getInstance();
    }
}
 
Example 10
Project: Rubicon   File: CommandTwitter.java   Source Code and License 6 votes vote down vote up
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
            .setOAuthConsumerKey(RubiconBot.getConfiguration().getString("twitterConsumerKey"))
            .setOAuthConsumerSecret(RubiconBot.getConfiguration().getString("twitterConsumerSecret"))
            .setOAuthAccessToken(RubiconBot.getConfiguration().getString("twitterAccessToken"))
            .setOAuthAccessTokenSecret(RubiconBot.getConfiguration().getString("twitterAccessTokenSecret"));
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    try {
        Status status = twitter.updateStatus(String.join(" ", parsedCommandInvocation.getArgs()));
        parsedCommandInvocation.getMessage().getTextChannel().sendMessage(new EmbedBuilder()
                .setDescription(status.getText())
                .setColor(new Color(0, 153, 229))
                .setAuthor("Take a look at the tweet on Twitter", "https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId(), "http://icons.iconarchive.com/icons/sicons/basic-round-social/512/twitter-icon.png")
                .setFooter(new SimpleDateFormat("dd.MM.yyyy hh:mm:ss").format(status.getCreatedAt()), null)
                .build()).queue();
    } catch (TwitterException e) {
        Logger.debug(e.getErrorMessage());
    }
    return null;
}
 
Example 11
Project: robird-reborn   File: BaseTwitterModel.java   Source Code and License 6 votes vote down vote up
private static Twitter configureTwitter(Account account) {
    final ConfigurationBuilder builder = new ConfigurationBuilder();

    builder.setOAuthConsumerKey(Config.TWITTER_CONSUMER_KEY);
    builder.setOAuthConsumerSecret(Config.TWITTER_CONSUMER_SECRET);
    builder.setOAuthAccessTokenSecret(account.tokenSecret());
    builder.setOAuthAccessToken(account.token());

    return new TwitterFactory(builder.build()).getInstance();
}
 
Example 12
Project: kafka-twitter-producer   File: TwitterProducerApp.java   Source Code and License 6 votes vote down vote up
@Bean
public TwitterStream twitterStream() {
	String consumerKey = environment.getRequiredProperty("consumerKey");
	String consumerSecret = environment.getRequiredProperty("consumerSecret");
	String accessToken = environment.getRequiredProperty("accessToken");
	String accessTokenSecret = environment.getRequiredProperty("accessTokenSecret");

	ConfigurationBuilder cb = new ConfigurationBuilder();
	cb.setOAuthConsumerKey(consumerKey);
	cb.setOAuthConsumerSecret(consumerSecret);
	cb.setOAuthAccessToken(accessToken);
	cb.setOAuthAccessTokenSecret(accessTokenSecret);
	cb.setJSONStoreEnabled(true);
	cb.setIncludeEntitiesEnabled(true);

	return new TwitterStreamFactory(cb.build()).getInstance();
}
 
Example 13
Project: yfiton   File: TwitterNotifier.java   Source Code and License 6 votes vote down vote up
public TwitterNotifier() throws NotificationException {
    super(CLIENT_ID, SECRET_ID,
            PromptReceiver.class,
            "com.yfiton.notifiers.twitter.TwitterWebEngineListener");

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder
            .setGZIPEnabled(true)
            .setDebugEnabled(true)
            .setOAuthConsumerKey(getClientId())
            .setOAuthConsumerSecret(getClientSecret());

    com.yfiton.notifiers.twitter.AccessToken accessToken = getAccessToken();

    if (accessToken != null) {
        configurationBuilder.setOAuthAccessToken(accessToken.getAccessToken());
        configurationBuilder.setOAuthAccessTokenSecret(accessToken.getAccessTokenSecret());
    }

    twitter =
            new TwitterFactory(
                    configurationBuilder.build()).getInstance();
}
 
Example 14
Project: The-NOC-List   File: TweetSearcher.java   Source Code and License 6 votes vote down vote up
public Twitter getTwitter() throws TwitterException, IOException 
{
   	ConfigurationBuilder cb = new ConfigurationBuilder();
   	
   	cb.setDebugEnabled(true)
   	  .setOAuthConsumerKey(CONSUMER_KEY)
   	  .setOAuthConsumerSecret(CONSUMER_SECRET)
   	  .setOAuthAccessToken(ACCESS_TOKEN)
   	  .setOAuthAccessTokenSecret(ACCESS_SECRET);
   	
   	TwitterFactory tf = new TwitterFactory(cb.build());
   	Twitter twitter = tf.getInstance();
   	
   	twitter.setOAuthAccessToken(new AccessToken(ACCESS_TOKEN, ACCESS_SECRET));

   	return twitter;
}
 
Example 15
Project: The-NOC-List   File: TweetLaunchpad.java   Source Code and License 6 votes vote down vote up
public Twitter getTwitter() throws TwitterException, IOException 
{
   	ConfigurationBuilder cb = new ConfigurationBuilder();
   	
   	cb.setDebugEnabled(true)
   	  .setOAuthConsumerKey(CONSUMER_KEY)
   	  .setOAuthConsumerSecret(CONSUMER_KEY_SECRET);
   	
   	TwitterFactory tf = new TwitterFactory(cb.build());
   	Twitter twitter = tf.getInstance();
   	
   	twitter.setOAuthAccessToken(new AccessToken(ACCESS_TOKEN, 
   												ACCESS_TOKEN_SECRET));

   	return twitter;
}
 
Example 16
Project: sociallink   File: SearchRunner.java   Source Code and License 6 votes vote down vote up
public static SearchRunner[] generateRunners(
        TwitterCredentials[] credentials,
        QueryAssemblyStrategy qaStrategy,
        ResultReceiver receiver
) throws TwitterException {
    SearchRunner[] runners = new SearchRunner[credentials.length];
    for (int i = 0; i < credentials.length; i++) {
        Twitter connection = new TwitterFactory(
                new ConfigurationBuilder()
                        .setOAuthConsumerKey(credentials[i].consumerKey)
                        .setOAuthConsumerSecret(credentials[i].consumerSecret)
                        .setOAuthAccessToken(credentials[i].token)
                        .setOAuthAccessTokenSecret(credentials[i].tokenSecret).build()
        ).getInstance();
        runners[i] = new SearchRunner(connection, qaStrategy, receiver);
    }
    return runners;
}
 
Example 17
Project: jacamo   File: Twitter.java   Source Code and License 6 votes vote down vote up
/**
 * Instantiate a twitter artifact configured with a consumer
 * key/secret and an access token/secret got for accessing
 * a Twitter account-
 */
void  init(String consumerKey, String consumerSecret, String accessToken, String accessSecret) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
         .setOAuthConsumerKey(consumerKey)
           .setOAuthConsumerSecret(consumerSecret)
           .setOAuthAccessToken(accessToken)
           .setOAuthAccessTokenSecret(accessSecret);

    factory = new TwitterFactory(cb.build());
    twitter = factory.getInstance();

    try {
        List<Status> statuses = twitter.getHomeTimeline();
        defineObsProperty("tw_user_status",statuses.get(0).getText());
    } catch (Exception ex){
        ex.printStackTrace();
        defineObsProperty("tw_user_status","");
    }
}
 
Example 18
Project: erad2016-streamprocessing   File: TwitterSpout.java   Source Code and License 6 votes vote down vote up
public void open(Map conf, TopologyContext context,
                 SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<String>(1000);
    this.collector = collector;

    StatusListener listener = new StatusListener() {
        public void onStatus(Status status) {
            queue.offer(TwitterObjectFactory.getRawJSON(status));
        }

        public void onDeletionNotice(StatusDeletionNotice sdn) { }
        public void onTrackLimitationNotice(int i) { }
        public void onScrubGeo(long l, long l1) { }
        public void onStallWarning(StallWarning stallWarning) { }
        public void onException(Exception e) { }
    };

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setJSONStoreEnabled(true);

    TwitterStreamFactory factory = new TwitterStreamFactory(cb.build());
    twitterStream = factory.getInstance();
    twitterStream.addListener(listener);
    twitterStream.filter(new FilterQuery().language("en").track("trump"));
}
 
Example 19
Project: discoursedb-core   File: ApplicationOnlyAuthTest.java   Source Code and License 6 votes vote down vote up
public void testSettingAccessToken1() throws TwitterException {
    // setup
    builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
    OAuth2Token token = new TwitterFactory(builder.build()).getInstance().getOAuth2Token();

    // exercise & verify
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setApplicationOnlyAuthEnabled(true);

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

    twitter.setOAuthConsumer(browserConsumerKey, browserConsumerSecret);
    twitter.setOAuth2Token(token);

    Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search");
    RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
    assertNotNull(searchTweetsRateLimit);
    assertEquals(searchTweetsRateLimit.getLimit(), 450);
}
 
Example 20
Project: discoursedb-core   File: ApplicationOnlyAuthTest.java   Source Code and License 6 votes vote down vote up
public void testSettingAccessToken2() throws TwitterException {
    // setup
    builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
    OAuth2Token token = new TwitterFactory(builder.build()).getInstance().getOAuth2Token();

    // exercise & verify
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setApplicationOnlyAuthEnabled(true);
    cb.setOAuthConsumerKey(browserConsumerKey);
    cb.setOAuthConsumerSecret(browserConsumerSecret);
    cb.setOAuth2TokenType(token.getTokenType());
    cb.setOAuth2AccessToken(token.getAccessToken());

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

    Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search");
    RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
    assertNotNull(searchTweetsRateLimit);
    assertEquals(searchTweetsRateLimit.getLimit(), 450);
}
 
Example 21
Project: discoursedb-core   File: AuthorizationTest.java   Source Code and License 6 votes vote down vote up
public void testOAuth2Instance() throws Exception {
    String consumerSecret = p.getProperty("browser.oauth.consumerSecret");
    String consumerKey = p.getProperty("browser.oauth.consumerSecret");

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setApplicationOnlyAuthEnabled(true);

    Twitter twitter = new TwitterFactory(cb.build()).getInstance();
    twitter.setOAuthConsumer(consumerKey, consumerSecret);
    try {
        twitter.setOAuthConsumer(consumerSecret, consumerKey);
        fail("should throw IllegalStateException");
    } catch (IllegalStateException ignore) {
    }

    Authorization auth = twitter.getAuthorization();
    assertTrue(auth instanceof OAuth2Authorization);
}
 
Example 22
Project: strata-2016-nyc-dl4j-rnn   File: LagerBot.java   Source Code and License 6 votes vote down vote up
public void init() throws TwitterException {
	
	ConfigurationBuilder cb = new ConfigurationBuilder();
	cb.setDebugEnabled(true)
	  .setOAuthConsumerKey("50S8DbHNUlryNiZ0PxRvp6GAC")
	  .setOAuthConsumerSecret("eMLgmvUyjd9hme7i7xTs4uzxk5Qm3tBi7mhtIQcMMjMl41tqi0")
	  .setOAuthAccessToken("776810737935257601-OtcUXTM7XDGthO8Yf194VM6MNAfHeWx")
	  .setOAuthAccessTokenSecret("VP2QqbSoecvK5vgQr7ySLBI0NoQPQ7oPXZhVOIdlPy7Fp");
	TwitterFactory tf = new TwitterFactory(cb.build());
	this.twitter = tf.getInstance();		
	
	//String review 
	
	
	this.loadLSTMModel();
	
}
 
Example 23
Project: Camel   File: TwitterConfiguration.java   Source Code and License 6 votes vote down vote up
/**
 * Builds a Twitter4J Configuration using the OAuth params.
 *
 * @return Configuration
 */
public Configuration getConfiguration() {
    checkComplete();
    ConfigurationBuilder confBuilder = new ConfigurationBuilder();
    confBuilder.setOAuthConsumerKey(consumerKey);
    confBuilder.setOAuthConsumerSecret(consumerSecret);
    confBuilder.setOAuthAccessToken(accessToken);
    confBuilder.setOAuthAccessTokenSecret(accessTokenSecret);
    if (getHttpProxyHost() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyHost());
    }
    if (getHttpProxyUser() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyUser());
    }
    if (getHttpProxyPassword() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyPassword());
    }
    if (httpProxyPort != null) {
        confBuilder.setHttpProxyPort(httpProxyPort);
    }
    
    return confBuilder.build();
}
 
Example 24
Project: govapps   File: ContentPortlet.java   Source Code and License 6 votes vote down vote up
private static void publish(String appName, long appid) {
    try {
    	String tweetString = "neuste App: http://www.govapps.de/?root=1&appid=" + appid + " " +  appName + " veröffentlicht.";
        _log.debug("tweetString: "+ tweetString);
    	ConfigurationBuilder cb = new ConfigurationBuilder();
    	cb.setDebugEnabled(false)
    	  .setOAuthConsumerKey("7ZVgfKiOvBDcDFpytRWSA")
    	  .setOAuthConsumerSecret("JmeJVeym78arzmGthrDUshQyhkq6nWA9tWLUKxc")
    	  .setOAuthAccessToken("1128008024-blkDYfot8A0DdKj6kznxtcDi122hMZoXCbQuzXT")
    	  .setOAuthAccessTokenSecret("c2YdcPPrB496YQ9QbYGXjNCVBavafCHWMbekAIRc");
    	TwitterFactory tf = new TwitterFactory(cb.build());
    	Twitter twitter = tf.getInstance();

        Status status = twitter.updateStatus(tweetString);
        _log.debug("Successfully updated the status to [" + status.getText() + "].");
//        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        _log.debug("Failed to get timeline: " + te.getMessage());
//        System.exit(-1);
    }
}
 
Example 25
Project: yfiton   File: TwitterNotifier.java   Source Code and License 6 votes vote down vote up
public TwitterNotifier() throws NotificationException {
    super(CLIENT_ID, SECRET_ID,
            PromptReceiver.class,
            "com.yfiton.notifiers.twitter.TwitterWebEngineListener");

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder
            .setGZIPEnabled(true)
            .setDebugEnabled(true)
            .setOAuthConsumerKey(getClientId())
            .setOAuthConsumerSecret(getClientSecret());

    com.yfiton.notifiers.twitter.AccessToken accessToken = getAccessToken();

    if (accessToken != null) {
        configurationBuilder.setOAuthAccessToken(accessToken.getAccessToken());
        configurationBuilder.setOAuthAccessTokenSecret(accessToken.getAccessTokenSecret());
    }

    twitter =
            new TwitterFactory(
                    configurationBuilder.build()).getInstance();
}
 
Example 26
Project: CZ4045-NLP-Crawler   File: Twitter4JTesting.java   Source Code and License 6 votes vote down vote up
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
	
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("P9sUs46f03m4xAJZzxt7Q");
    cb.setOAuthConsumerSecret("Czw2g7QoURXz5WoLE8AbMounBiVAONktlQP1YleEy0");
    cb.setOAuthAccessToken("182798423-gFyyrktqZmcrTu916G7zTkNX3pnTsB8Zc4s22dOc");
    cb.setOAuthAccessTokenSecret("ITKJnDENspq5dVZIQMjTtG4NOj2ioT0QE2DkE9ZZA");

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

    CStreamListener objStreamListener = new CStreamListener();

    FilterQuery fq = new FilterQuery();

    String [] keywords = TwitterConst.KEYWORDS;

    fq.track(keywords);

    twitterStream.addListener(objStreamListener);
    twitterStream.filter(fq);
}
 
Example 27
Project: RavenBot   File: TwitterHandler.java   Source Code and License 6 votes vote down vote up
public TwitterHandler() {
	ConfigurationBuilder cb = new ConfigurationBuilder();
	Settings current = SettingsManager.getInstance().getSettings();
	cb.setDebugEnabled(true)
			.setOAuthConsumerKey(current.getTwitCKey())
			.setOAuthConsumerSecret(current.getTwitCSecret())
			.setOAuthAccessToken(current.getTwitToken())
			.setOAuthAccessTokenSecret(current.getTwitTSecret());
	TwitterFactory tf = new TwitterFactory(cb.build());
	twitter = tf.getInstance();
	try {
		System.out.println("Twitter User ID: " + twitter.getId());
		System.out.println("Twitter Screen Name: " + twitter.getScreenName());
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 28
Project: simmo-stream-manager   File: TwitterRetriever.java   Source Code and License 6 votes vote down vote up
public TwitterRetriever(Credentials credentials) throws Exception {
	
	super(credentials);
	
	if (credentials.getKey() == null || credentials.getSecret() == null ||
			credentials.getAccessToken() == null || credentials.getAccessTokenSecret() == null) {
		logger.error("Twitter requires authentication.");
		throw new Exception("Twitter requires authentication.");
	}
	
	ConfigurationBuilder cb = new ConfigurationBuilder();
	cb.setJSONStoreEnabled(false)
		.setOAuthConsumerKey(credentials.getKey())
		.setOAuthConsumerSecret(credentials.getSecret())
		.setOAuthAccessToken(credentials.getAccessToken())
		.setOAuthAccessTokenSecret(credentials.getAccessTokenSecret());
	Configuration conf = cb.build();
	
	this.tf = new TwitterFactory(conf);
	twitter = tf.getInstance();

}
 
Example 29
Project: taskerbox   File: TwitterChannel.java   Source Code and License 6 votes vote down vote up
@Override
public void setup() throws IllegalStateException, TwitterException {
  logInfo(log, "Twitter setup...");

  ConfigurationBuilder cb = new ConfigurationBuilder();
  cb.setDebugEnabled(true).setOAuthConsumerKey(this.consumerKey)
      .setOAuthConsumerSecret(this.consumerSecret).setOAuthAccessToken(this.accessToken)
      .setOAuthAccessTokenSecret(this.accessTokenSecret);
  TwitterFactory tf = new TwitterFactory(cb.build());

  this.twitter = tf.getInstance();

  this.loggedUser = this.twitter.getScreenName();

  logInfo(log, "Twitter setup finished! Logged user is " + this.loggedUser);
}
 
Example 30
Project: BotLibre   File: Twitter.java   Source Code and License 6 votes vote down vote up
public void connect() throws TwitterException {
	initProperties();
	ConfigurationBuilder config = new ConfigurationBuilder();
	config.setOAuthConsumerKey(getOauthKey());
	config.setOAuthConsumerSecret(getOauthSecret());
	config.setOAuthAccessToken(getToken());
	config.setOAuthAccessTokenSecret(getTokenSecret());
	twitter4j.Twitter twitter = new TwitterFactory(config.build()).getInstance();
	User user = twitter.verifyCredentials();
	if (!this.userName.equals(user.getScreenName())) {
		this.userName = user.getScreenName();
		saveProperties(null);
	}
	//AccessToken accessToken = new AccessToken(getToken(), getTokenSecret());
	//twitter4j.Twitter twitter = new TwitterFactory().getInstance(accessToken);
	//twitter4j.Twitter twitter = new TwitterFactory().getInstance(getOauthKey(), getOauthSecret(), accessToken);
	//twitter4j.Twitter twitter = new TwitterFactory().getInstance(getUsername(), getPassword());
       setConnection(twitter);
}
 
Example 31
Project: ire-seimp   File: TwitterManager.java   Source Code and License 6 votes vote down vote up
public static Twitter getTwitterInstance() throws TwitterException {
	if (twitter == null) {
		final ConfigurationBuilder cb = new ConfigurationBuilder();
		cb.setDebugEnabled(true);
		cb.setApplicationOnlyAuthEnabled(true);

		final OAuth2Token token = getOAuth2Token();
		cb.setOAuth2TokenType(token.getTokenType());
		cb.setOAuth2AccessToken(token.getAccessToken());

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

	return twitter;
}
 
Example 32
Project: peak-forecast   File: TwitterImpl.java   Source Code and License 6 votes vote down vote up
@Override
public void updateStatus(String message) {
	try {
		
		ConfigurationBuilder cb = new ConfigurationBuilder();
		//info OAuth settings de l'application twitter tweetpeakforecast enregistré par l'utilisateur @peakforecast 
		cb.setDebugEnabled(true)
		  .setOAuthConsumerKey("0PqersXnGOn7AirB13jszw")
		  .setOAuthConsumerSecret("r3qyCuhmwRI90JY04kqcYtn5yEl6yaW1UoRhAY08Q")
		  .setOAuthAccessToken("1598158057-epoKcN3Lfz405zjNZQ2rl5cx74lthvBZ93cCsfj")
		  .setOAuthAccessTokenSecret("6YwDPdjS7OpqDHb6PsmW0beOjCgjITzDGYV89gtQU");
		TwitterFactory tf = new TwitterFactory(cb.build());
		Twitter twitter = tf.getInstance();
		Status status = twitter.updateStatus(message);
		System.out.println("Successfully updated the status to [" + status.getText() + "].");
	
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 33
Project: MEater   File: TimelineStream.java   Source Code and License 6 votes vote down vote up
/**
 * <p>
 * Creates a new {@code TimelineStream} instance with the given OAuth
 * information to use for collection.
 * </p>
 * 
 * @param consumerKey
 *            the Twitter consumer key to use
 * @param consumerSecret
 *            the Twitter consumer secret to use
 * @param accessToken
 *            the Twitter access token to use
 * @param accessTokenSecret
 *            the Twitter access token secret to use
 */
public TimelineStream(String consumerKey, String consumerSecret,
		String accessToken, String accessTokenSecret) {
	this.setShouldShutdown(false);
	this.setShutdownWhenEmpty(false);

	this.userIds = new LinkedBlockingQueue<Long>();
	this.listeners = new HashSet<TimelineStreamListener>();

	// get oauth -> build twitter collection object
	ConfigurationBuilder cb = new ConfigurationBuilder();
	cb.setOAuthConsumerKey(consumerKey);
	cb.setOAuthConsumerSecret(consumerSecret);
	cb.setOAuthAccessToken(accessToken);
	cb.setOAuthAccessTokenSecret(accessTokenSecret);

	// (timeout from original TLC code)
	cb.setHttpConnectionTimeout(40000);
	this.twitter = new TwitterFactory(cb.build()).getInstance();
}
 
Example 34
Project: firebase-login-demo-android   File: TwitterOAuthActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // setup twitter client
    mTwitter = new TwitterFactory(new ConfigurationBuilder()
            .setOAuthConsumerKey(getResources().getString(R.string.twitter_consumer_key))
            .setOAuthConsumerSecret(getResources().getString(R.string.twitter_consumer_secret))
            .build()).getInstance();

    // setup twitter webview
    mTwitterView = new WebView(this);
    mTwitterView.getSettings().setJavaScriptEnabled(true);

    // initialize view
    setContentView(mTwitterView);

    // start the web view
    loginToTwitter();
}
 
Example 35
Project: 30-android-libraries-in-30-days   File: Twitter4jActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.day22_activity_twitter4j);

    mTweet = (EditText) findViewById(R.id.text_tweet);
    mButtonTweet = (Button) findViewById(R.id.button_tweet);
    mListView = (ListView) findViewById(R.id.list_view);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
            .setOAuthConsumerKey(API_KEY)
            .setOAuthConsumerSecret(API_SECRET)
            .setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);
    mFactory = new TwitterFactory(cb.build());

    new AsyncTimeline().execute();

    mButtonTweet.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AsyncTweet().execute();
        }
    });
}
 
Example 36
Project: storm-example   File: TweetEmitter.java   Source Code and License 6 votes vote down vote up
public TweetEmitter() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("DJSv02qbCiCVY6Sy8uz8Cg")
            .setOAuthConsumerSecret("iVa3GGSl9NrHvu3AAXm6zBV7Z2XTvtuDkAMiArHlGM")
            .setOAuthAccessToken("1353264175-5EWRtEHoaJ6zfmAG5BEn7Uc7E8qg7P531oddm08")
            .setOAuthAccessTokenSecret("ss7YCprReDBEpm4AGnguqB1xNCUwyRGli5Q33yImf0");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
    query = new Query(SEARCH_PHRASE);
    query.setLang("en");
    long now = System.currentTimeMillis();
    if (now - lastFetch > FETCH_PERIODICITY) {
        try {
            result = twitter.search(query);
        } catch (TwitterException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example 37
Project: Floata-Client   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected Void doInBackground(Void... voids) {

	ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
	configurationBuilder
			.setOAuthConsumerKey(getString(R.string.TWITTER_CONSUMER_KEY));
	configurationBuilder
			.setOAuthConsumerSecret(getString(R.string.TWITTER_CONSUMER_SECRET));
	Configuration configuration = configurationBuilder.build();
	twitter = new TwitterFactory(configuration).getInstance();

	try {
		RequestToken requestToken = twitter
				.getOAuthRequestToken(getString(R.string.TWITTER_CALLBACK_URL));
		launchLoginWebView(requestToken);
	} catch (TwitterException e) {
		e.printStackTrace();

	}
	return null;
}
 
Example 38
Project: Floata-Client   File: Floating.java   Source Code and License 6 votes vote down vote up
/**
 * getting Places JSON
 * */
protected String doInBackground(String... args) {

	String status = args[0];
	try {
		ConfigurationBuilder builder = new ConfigurationBuilder();
		builder.setOAuthConsumerKey(getString(R.string.TWITTER_CONSUMER_KEY));
		builder.setOAuthConsumerSecret(getString(R.string.TWITTER_CONSUMER_SECRET));

		AccessToken accessToken = new AccessToken(access_token,
				access_token_secret);
		 twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

		response = twitter.updateStatus(status);
		

	} catch (TwitterException e) {

	}
	return null;
}
 
Example 39
Project: Twitter-j4   File: MyActivity.java   Source Code and License 6 votes vote down vote up
public void loginTwitter(){
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
    builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
    Configuration configuration = builder.build();

    TwitterFactory factory = new TwitterFactory(configuration);
    Twitter twitter = factory.getInstance();

    try {
        requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);

        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
    } catch (TwitterException e) {
        e.printStackTrace();
    }
}
 
Example 40
Project: TweetyHunting   File: TwitterManager.java   Source Code and License 6 votes vote down vote up
/**
 * Try to connect to the Twitter API
 */
public void connect() {
    if (isConnected()) {
        String oauthAccessToken = mSharedPreferences.getString(Constant.PREF_KEY_TOKEN, "");
        String oAuthAccessTokenSecret = mSharedPreferences.getString(Constant.PREF_KEY_SECRET, "");
        ConfigurationBuilder confbuilder = new ConfigurationBuilder();
        Configuration conf = confbuilder
                .setOAuthConsumerKey(Constant.CONSUMER_KEY)
                .setOAuthConsumerSecret(Constant.CONSUMER_SECRET)
                .setOAuthAccessToken(oauthAccessToken)
                .setOAuthAccessTokenSecret(oAuthAccessTokenSecret)
                .build();
        mListener.onConnect();
    } else {
        mListener.onDisconnect();
    }
}
 
Example 41
Project: UniLink   File: Main.java   Source Code and License 6 votes vote down vote up
@Override
protected Void doInBackground(Object... objects) {
    userlist=objects[0];
    ConfigurationBuilder cb = new ConfigurationBuilder();
    //cb.setApplicationOnlyAuthEnabled(true);
    cb.setDebugEnabled(true)
            .setOAuthConsumerKey("dWaJ5ZaaGVVvxQIu0Tsw")
            .setOAuthConsumerSecret("EeVAXbSNQFS4q7WxLXpIuKeCL4QIs4sDynLlt3Gaiw")
            .setOAuthAccessToken("2157036348-0nQc6dFkGRuPYeWBKTFGxGX0CGq5AXblDKX9GRC")
            .setOAuthAccessTokenSecret("CGR50c88AJCuIH7a5E5iy0GYsG8tf7rLA7OqXwJqv6mWN");
    try{
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
    String s = twitter.getScreenName();
    }
    catch (Exception ex){
        //Toast.makeText(Main.this,"Twitter app auth failed",Toast.LENGTH_SHORT).show();
        twitter=null;
    }
    return null;
}
 
Example 42
Project: Twitter4JAndroidLogin   File: TwitterAdapter.java   Source Code and License 6 votes vote down vote up
private void init(){
	activity = (Activity) context;
	sharedPrefs = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
		
	ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
	configurationBuilder.setOAuthConsumerKey(appKey);
	configurationBuilder.setOAuthConsumerSecret(appSecret);
	Configuration configuration = configurationBuilder.build();
	twitterFactory = new TwitterFactory(configuration);
	
	String tokenKey = sharedPrefs.getString(PREF_KEY_TOKEN, null);
	String tokenSecret = sharedPrefs.getString(PREF_KEY_SECRET, null);
	
	accessToken = tokenKey != null ? new AccessToken(tokenKey, tokenSecret) : null;
	twitter = isConnected() ? twitterFactory.getInstance(accessToken) : twitterFactory.getInstance();
}
 
Example 43
Project: interop   File: Twitter2Json.java   Source Code and License 6 votes vote down vote up
public Twitter2Json(final String userId,
                     final Query query,
                     final int total,
                     final Date lowerDate,
                     final boolean useRetweets) throws TwitterException {
    assert ((userId != null) || (query != null));
    assert ((total >= 1) || (lowerDate != null));
    
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
      .setOAuthConsumerKey("LmvfpL4pJE7PJr0CgJUuQKZOy")
      .setOAuthConsumerSecret("UP1VIf4K3jGDvOYYXh0zshHnuj8HSUMDTWlJEEhGMWIJHKGXSJ")
      .setOAuthAccessToken("2788081964-9C7j4ZBOsdIy9tmtMkong54QimvjkwopXdLqecm")
      .setOAuthAccessTokenSecret("swwqLPLWppweF3KRKe2zpU9qPNFDbsZm9OqQ5scX9vVCp");

    final Twitter twitter = new TwitterFactory(cb.build()).getInstance();
    
    this.loader = new TweetLoader(twitter, userId, query, total, lowerDate, 
                                                               useRetweets);
    next = getNext();
}
 
Example 44
Project: tycka   File: TickerActivity.java   Source Code and License 6 votes vote down vote up
/**
 * Function to login twitter
 * */
private void loginToTwitter() {
    // Check if already logged in
    if (!isTwitterLoggedInAlready()) {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
        builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
        Configuration configuration = builder.build();
         
        TwitterFactory factory = new TwitterFactory(configuration);
        twitter = factory.getInstance();
 
        try {
            requestToken = twitter
                    .getOAuthRequestToken(TWITTER_CALLBACK_URL);
            this.startActivity(new Intent(Intent.ACTION_VIEW, Uri
                    .parse(requestToken.getAuthenticationURL())));
        } catch (TwitterException e) {
            e.printStackTrace();
        }
    } else {
        // user already logged into twitter
        Toast.makeText(getApplicationContext(),
                "Already Logged into twitter", Toast.LENGTH_LONG).show();
    }
}
 
Example 45
Project: Twiteckon   File: TwitterApp.java   Source Code and License 6 votes vote down vote up
protected void onResume() {
	super.onResume();

	if (isConnected()) {
		String oauthAccessToken = mSharedPreferences.getString(Const.PREF_KEY_TOKEN, "");
		String oAuthAccessTokenSecret = mSharedPreferences.getString(Const.PREF_KEY_SECRET, "");

		ConfigurationBuilder confbuilder = new ConfigurationBuilder();
		Configuration conf = confbuilder.setOAuthConsumerKey(Const.TWITTER_CONSUMER_KEY).setOAuthConsumerSecret(Const.TWITTER_CONSUMER_SECRET).setOAuthAccessToken(oauthAccessToken).setOAuthAccessTokenSecret(oAuthAccessTokenSecret).build();
		twitterStream = new TwitterStreamFactory(conf).getInstance();
		// Starting streaming
		startStreamingTimeline();
		isTwitterStreamRunning = true;
		getTweetButton.setText("stop streaming");
		// -----
		twitterButtonLogin.setText(R.string.label_disconnect);
		getTweetButton.setEnabled(true);
	} else {
		twitterButtonLogin.setText(R.string.label_connect);
	}
}
 
Example 46
Project: image-verification-corpus   File: DatasetFeaturesExtractor.java   Source Code and License 6 votes vote down vote up
/**
 * Creates the connection to Twitter API.
 * @return Twitter object for the current connection
 */
public static Twitter connectToTwitterAPI() {

	ConfigurationBuilder cb = new ConfigurationBuilder();
	/*please fill in your credentials*/
	cb.setDebugEnabled(true).setOAuthConsumerKey("CONSUMER_KEY")
			.setOAuthConsumerSecret("CONSUMER_SECRET")
			.setOAuthAccessToken("ACCESS_TOKEN")
			.setOAuthAccessTokenSecret("ACCESS_TOKEN_SECRET");

	cb.setJSONStoreEnabled(true);

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

	return twitter;
}
 
Example 47
Project: MindRDR   File: OAuthActivity.java   Source Code and License 6 votes vote down vote up
protected boolean verifyTwitterCredentials()
{
    Twitter twitter;
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(mOAuthData.getConsumerKey());
    cb.setOAuthConsumerSecret(mOAuthData.getConsumerSecret());
    cb.setOAuthAccessToken(mOAuthData.getAccessToken());
    cb.setOAuthAccessTokenSecret(mOAuthData.getAccessTokenSecret());


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

    try {
        User user = twitter.verifyCredentials();
        return true;

    } catch (TwitterException te) {
        return false;
    }
}
 
Example 48
Project: cf-twitter-gateway   File: RailoTwitterUserStreamGateway.java   Source Code and License 6 votes vote down vote up
/**
 * Initializes this gateway
 */
@Override
@SuppressWarnings("rawtypes")
public void init(final GatewayEngine engine, final String id, final String cfcPath, final Map config) throws IOException
{
  try
  {
    this.argType = ArgumentType.fromConfigValue((String) config.get(ARGUMENT_TYPE));
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey((String) config.get(OAUTH_CONSUMER_KEY));
    cb.setOAuthConsumerSecret((String) config.get(OAUTH_CONSUMER_SECRET));
    cb.setOAuthAccessToken((String) config.get(OAUTH_ACCESS_TOKEN));
    cb.setOAuthAccessTokenSecret((String) config.get(OAUTH_ACCESS_SECRET));
    cb.setUserStreamRepliesAllEnabled(Boolean.valueOf((String) config.get(ALL_REPLIES)));
    cb.setJSONStoreEnabled(ArgumentType.JSON.equals(this.argType));
    super.init(engine, id, new TwitterUserStream(this, cb.build()));
  }
  catch (Throwable t)
  {
    final IOException ex = new IOException("Unable to initialize gateway", t);
    this.onException(ex);
    throw ex;
  }
}
 
Example 49
Project: skandroid-core   File: TwitpicImageUpload.java   Source Code and License 6 votes vote down vote up
/**
 * Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [message]
 *
 * @param args message
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [image file path] [message]");
        System.exit(-1);
    }
    try {
        Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(args[0]).build();
        ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.TWITPIC);
        String url;
        if (args.length >= 3) {
            url = upload.upload(new File(args[1]), args[2]);
        } else {
            url = upload.upload(new File(args[1]));
        }
        System.out.println("Successfully uploaded image to Twitpic at " + url);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to upload the image: " + te.getMessage());
        System.exit(-1);
    }
}
 
Example 50
Project: skandroid-core   File: PlixiImageUpload.java   Source Code and License 6 votes vote down vote up
/**
 * Usage: java twitter4j.examples.media.PlixiImageUpload [image file path] [message]
 *
 * @param args message
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.media.PlixiImageUpload [API key] [image file path] [message]");
        System.exit(-1);
    }
    try {
        Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(args[0]).build();
        ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.PLIXI);
        String url;
        if (args.length >= 3) {
            url = upload.upload(new File(args[1]), args[2]);
        } else {
            url = upload.upload(new File(args[1]));
        }
        System.out.println("Successfully uploaded image to Plixi at " + url);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to upload the image: " + te.getMessage());
        System.exit(-1);
    }
}
 
Example 51
Project: skandroid-core   File: ApplicationOnlyAuthTest.java   Source Code and License 6 votes vote down vote up
public void testSettingAccessToken1() throws TwitterException {
    // setup
    builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
    OAuth2Token token = new TwitterFactory(builder.build()).getInstance().getOAuth2Token();

    // exercise & verify
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setUseSSL(true);
    cb.setApplicationOnlyAuthEnabled(true);

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

    twitter.setOAuthConsumer(browserConsumerKey, browserConsumerSecret);
    twitter.setOAuth2Token(token);

    Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search");
    RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
    assertNotNull(searchTweetsRateLimit);
    assertEquals(searchTweetsRateLimit.getLimit(), 450);
}
 
Example 52
Project: skandroid-core   File: ApplicationOnlyAuthTest.java   Source Code and License 6 votes vote down vote up
public void testSettingAccessToken2() throws TwitterException {
    // setup
    builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
    OAuth2Token token = new TwitterFactory(builder.build()).getInstance().getOAuth2Token();

    // exercise & verify
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setUseSSL(true);
    cb.setApplicationOnlyAuthEnabled(true);
    cb.setOAuthConsumerKey(browserConsumerKey);
    cb.setOAuthConsumerSecret(browserConsumerSecret);
    cb.setOAuth2TokenType(token.getTokenType());
    cb.setOAuth2AccessToken(token.getAccessToken());

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

    Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search");
    RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
    assertNotNull(searchTweetsRateLimit);
    assertEquals(searchTweetsRateLimit.getLimit(), 450);
}
 
Example 53
Project: skandroid-core   File: ApplicationOnlyAuthTest.java   Source Code and License 6 votes vote down vote up
public void testRequiringSSL() {
    // setup
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setUseSSL(false);
    cb.setOAuth2TokenURL("http://api.twitter.com/oauth2/token");
    cb.setApplicationOnlyAuthEnabled(true);

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

    // exercise & verify
    twitter.setOAuthConsumer(browserConsumerKey, browserConsumerSecret);
    try {
        twitter.getOAuth2Token();
        fail("should throw TwitterException");

    } catch (TwitterException ignore) {
    }
}
 
Example 54
Project: skandroid-core   File: AuthorizationTest.java   Source Code and License 6 votes vote down vote up
public void testOAuth2Instance() throws Exception {
    String consumerSecret = p.getProperty("browser.oauth.consumerSecret");
    String consumerKey = p.getProperty("browser.oauth.consumerSecret");

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setApplicationOnlyAuthEnabled(true);
    cb.setUseSSL(true);

    Twitter twitter = new TwitterFactory(cb.build()).getInstance();
    twitter.setOAuthConsumer(consumerKey, consumerSecret);
    try {
        twitter.setOAuthConsumer(consumerSecret, consumerKey);
        fail("should throw IllegalStateException");
    } catch (IllegalStateException ignore) {
    }

    Authorization auth = twitter.getAuthorization();
    assertTrue(auth instanceof OAuth2Authorization);
}
 
Example 55
Project: skandroid-core   File: MediaUploadTest.java   Source Code and License 6 votes vote down vote up
public void testProviders() throws Exception {
    Configuration conf;
    ImageUploadFactory factory;
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.TWITTER.name()).build();
    factory = new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.IMG_LY.name()).build();
    factory = new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.PLIXI.name()).build();
    factory = new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.TWIPPLE.name()).build();
    factory = new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.TWITGOO.name()).build();
    factory = new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.TWITPIC.name()).build();
    factory = new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.YFROG.name()).build();
    factory = new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.MOBYPICTURE.name()).build();
    factory = new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.POSTEROUS.name()).build();
    factory = new ImageUploadFactory(conf);
}
 
Example 56
Project: kafka-producers   File: TwitterProducer.java   Source Code and License 6 votes vote down vote up
@Override
public void configure(Properties props) {
	ProducerConfig config = new ProducerConfig(props);
	producer = new Producer<String, String>(config);
	
	// The necessary authentication keys to connect to twitter API v1.1
    String consumerKey = props.getProperty(TwitterProducerConstants.CONSUMER_KEY_KEY);
    String consumerSecret = props.getProperty(TwitterProducerConstants.CONSUMER_SECRET_KEY);
    String accessToken = props.getProperty(TwitterProducerConstants.ACCESS_TOKEN_KEY);
    String accessTokenSecret = props.getProperty(TwitterProducerConstants.ACCESS_TOKEN_SECRET_KEY);
	
	ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
}
 
Example 57
Project: QMAClone   File: TwitterClient.java   Source Code and License 6 votes vote down vote up
@Inject
public TwitterClient(Database database) {
  String consumerKey;
  String consumerSecret;
  String token;
  String tokenSecret;
  try {
    consumerKey = database.getPassword("twitter_consumer_key");
    consumerSecret = database.getPassword("twitter_consumer_secret");
    token = database.getPassword("twitter_access_token");
    tokenSecret = database.getPassword("twitter_access_token_secret");
  } catch (DatabaseException e) {
    logger.log(Level.WARNING, "Failed to get tokens for Twitter.", e);
    twitterFactory = null;
    return;
  }

  ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
  configurationBuilder.setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
      .setOAuthAccessToken(token).setOAuthAccessTokenSecret(tokenSecret);
  twitterFactory = new TwitterFactory(configurationBuilder.build());
}
 
Example 58
Project: spotthestation   File: TwitterActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected String doInBackground(String... uri) {
	publishProgress("");
	String accessToken = settings.getString("twitter_access_token", null);
	String accessTokenSecret = settings.getString("twitter_access_token_secret", null);
	Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(TWITPIC_API_KEY).setOAuthConsumerKey(OAUTH_CONSUMER_KEY).setOAuthConsumerSecret(OAUTH_CONSUMER_SECRET).setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret).build();
	Twitter twitter = new TwitterFactory(conf).getInstance();
	try {
		File file = new File(fileUriPath);
		if (file != null) {
			StatusUpdate status = new StatusUpdate(statusString);
			status.setMedia(file);
			twitter.updateStatus(status);
		}
	}
	catch (TwitterException e) {
		Log.d("TAG", "Twitter Exception: Photo not uploaded" + e.getErrorMessage());
	}
	return "Done";
}
 
Example 59
Project: cafeUnoesc   File: TwitpicImageUpload.java   Source Code and License 6 votes vote down vote up
/**
 * Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [message]
 *
 * @param args message
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [image file path] [message]");
        System.exit(-1);
    }
    try {
        Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(args[0]).build();
        ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.TWITPIC);
        String url;
        if (args.length >= 3) {
            url = upload.upload(new File(args[1]), args[2]);
        } else {
            url = upload.upload(new File(args[1]));
        }
        System.out.println("Successfully uploaded image to Twitpic at " + url);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to upload the image: " + te.getMessage());
        System.exit(-1);
    }
}
 
Example 60
Project: cafeUnoesc   File: PlixiImageUpload.java   Source Code and License 6 votes vote down vote up
/**
 * Usage: java twitter4j.examples.media.PlixiImageUpload [image file path] [message]
 *
 * @param args message
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.media.PlixiImageUpload [API key] [image file path] [message]");
        System.exit(-1);
    }
    try {
        Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(args[0]).build();
        ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.PLIXI);
        String url;
        if (args.length >= 3) {
            url = upload.upload(new File(args[1]), args[2]);
        } else {
            url = upload.upload(new File(args[1]));
        }
        System.out.println("Successfully uploaded image to Plixi at " + url);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to upload the image: " + te.getMessage());
        System.exit(-1);
    }
}