Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
S4-138: update twitter example with new twitter authentication scheme…
Browse files Browse the repository at this point in the history
… (oauth)

patch from Kurtt Lin

It includes:
1. authentication method change from username/password pair to oauth(consumerKey/consumerSecret/accessToken/accessTokenSecret)
2. twitter4j dependencies update from 2.2.5 to 3.0.3
  • Loading branch information
matthieumorel committed Sep 8, 2013
1 parent 9fdee24 commit 276a497
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
Expand Up @@ -50,8 +50,8 @@ repositories {

/* All project libraries must be defined here. */
project.ext["libraries"] = [
// for instance, adding twitter4j 2.2.5 will be:
//twitter4j_core: 'org.twitter4j:twitter4j-core:2.2.5'
// for instance, adding twitter4j 3.0.3 will be:
//twitter4j_core: 'org.twitter4j:twitter4j-core:3.0.3'
// http://mvnrepository.com/ is a good source
// if you need to use a different repository, please specify it in the above "repositories" block

Expand Down
4 changes: 2 additions & 2 deletions test-apps/twitter-adapter/build.gradle
Expand Up @@ -71,8 +71,8 @@ repositories {

/* All project libraries must be defined here. */
project.ext["libraries"] = [
twitter4j_core: 'org.twitter4j:twitter4j-core:2.2.5',
twitter4j_stream: 'org.twitter4j:twitter4j-stream:2.2.5',
twitter4j_core: 'org.twitter4j:twitter4j-core:3.0.3',
twitter4j_stream: 'org.twitter4j:twitter4j-stream:3.0.3',
s4_base: 'org.apache.s4:s4-base:0.6.0-incubating',
s4_comm: 'org.apache.s4:s4-comm:0.6.0-incubating',
s4_core: 'org.apache.s4:s4-core:0.6.0-incubating'
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import twitter4j.StallWarning;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
Expand Down Expand Up @@ -66,17 +67,20 @@ public void connectAndRead() throws Exception {
File twitter4jPropsFile = new File(System.getProperty("user.home") + "/twitter4j.properties");
if (!twitter4jPropsFile.exists()) {
logger.error(
"Cannot find twitter4j.properties file in this location :[{}]. Make sure it is available at this place and includes user/password credentials",
"Cannot find twitter4j.properties file in this location :[{}]. Make sure it is available at this place and includes oauth.consumerKey/oauth.consumerSecret/oauth.accessToken/oauth.accessTokenSecret credentials",
twitter4jPropsFile.getAbsolutePath());
return;
}
twitterProperties.load(new FileInputStream(twitter4jPropsFile));

cb.setDebugEnabled(Boolean.valueOf(twitterProperties.getProperty("debug")))
.setUser(twitterProperties.getProperty("user")).setPassword(twitterProperties.getProperty("password"));
.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey"))
.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret"))
.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken"))
.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret"));

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

@Override
public void onException(Exception ex) {
logger.error("error", ex);
Expand All @@ -90,7 +94,6 @@ public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
@Override
public void onStatus(Status status) {
messageQueue.add(status);

}

@Override
Expand All @@ -102,10 +105,14 @@ public void onScrubGeo(long userId, long upToStatusId) {
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
logger.error("error");
}

@Override
public void onStallWarning(StallWarning arg0) {
logger.error("error");
}
};
twitterStream.addListener(statusListener);
twitterStream.sample();

}

@Override
Expand All @@ -119,7 +126,6 @@ protected void onStart() {
}

class Dequeuer implements Runnable {

@Override
public void run() {
while (true) {
Expand All @@ -129,10 +135,8 @@ public void run() {
event.put("statusText", String.class, status.getText());
getRemoteStream().put(event);
} catch (Exception e) {

}
}

}
}
}
8 changes: 5 additions & 3 deletions test-apps/twitter-counter/README.txt
Expand Up @@ -23,9 +23,11 @@ Architecture:
How to configure:
- you need a twitter4j.properties file in your home dir, with the following properties filled:
debug=true|false
user=<a twitter user name>
password=<the matching password>
oauth.consumerKey=<a twitter app consumer key>
oauth.consumerSecret=<the matching app consumer secret>
oauth.accessToken=<a twitter account access token>
oauth.accessTokenSecret=<the matching twitter account access token secret>

How to run:

Please follow the instructions in the S4 piper walkthrough on the documentation from the website
Please follow the instructions in the S4 piper walkthrough on the documentation from the website

0 comments on commit 276a497

Please sign in to comment.