incubator-s4-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject git commit: S4-138: update twitter example with new twitter authentication scheme (oauth)
Date Sun, 08 Sep 2013 13:28:28 GMT
Updated Branches:
  refs/heads/dev 9fdee24c9 -> 276a49772


S4-138: update twitter example with new twitter authentication scheme (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


Project: http://git-wip-us.apache.org/repos/asf/incubator-s4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s4/commit/276a4977
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s4/tree/276a4977
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s4/diff/276a4977

Branch: refs/heads/dev
Commit: 276a49772f00a7880d270941a8e05c878ee2484e
Parents: 9fdee24
Author: Matthieu Morel <mmorel@apache.org>
Authored: Sun Sep 8 14:37:14 2013 +0200
Committer: Matthieu Morel <mmorel@apache.org>
Committed: Sun Sep 8 14:37:14 2013 +0200

----------------------------------------------------------------------
 .../src/main/resources/templates/build.gradle   |  4 ++--
 test-apps/twitter-adapter/build.gradle          |  4 ++--
 .../s4/example/twitter/TwitterInputAdapter.java | 20 ++++++++++++--------
 test-apps/twitter-counter/README.txt            |  8 +++++---
 4 files changed, 21 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/276a4977/subprojects/s4-tools/src/main/resources/templates/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/s4-tools/src/main/resources/templates/build.gradle b/subprojects/s4-tools/src/main/resources/templates/build.gradle
index 82bc5a1..04508e2 100644
--- a/subprojects/s4-tools/src/main/resources/templates/build.gradle
+++ b/subprojects/s4-tools/src/main/resources/templates/build.gradle
@@ -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
 

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/276a4977/test-apps/twitter-adapter/build.gradle
----------------------------------------------------------------------
diff --git a/test-apps/twitter-adapter/build.gradle b/test-apps/twitter-adapter/build.gradle
index e654957..340f9a7 100644
--- a/test-apps/twitter-adapter/build.gradle
+++ b/test-apps/twitter-adapter/build.gradle
@@ -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'

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/276a4977/test-apps/twitter-adapter/src/main/java/org/apache/s4/example/twitter/TwitterInputAdapter.java
----------------------------------------------------------------------
diff --git a/test-apps/twitter-adapter/src/main/java/org/apache/s4/example/twitter/TwitterInputAdapter.java
b/test-apps/twitter-adapter/src/main/java/org/apache/s4/example/twitter/TwitterInputAdapter.java
index 9afb04e..1bd7725 100644
--- a/test-apps/twitter-adapter/src/main/java/org/apache/s4/example/twitter/TwitterInputAdapter.java
+++ b/test-apps/twitter-adapter/src/main/java/org/apache/s4/example/twitter/TwitterInputAdapter.java
@@ -29,6 +29,7 @@ import org.apache.s4.core.adapter.AdapterApp;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import twitter4j.StallWarning;
 import twitter4j.Status;
 import twitter4j.StatusDeletionNotice;
 import twitter4j.StatusListener;
@@ -66,17 +67,20 @@ public class TwitterInputAdapter extends AdapterApp {
         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);
@@ -90,7 +94,6 @@ public class TwitterInputAdapter extends AdapterApp {
             @Override
             public void onStatus(Status status) {
                 messageQueue.add(status);
-
             }
 
             @Override
@@ -102,10 +105,14 @@ public class TwitterInputAdapter extends AdapterApp {
             public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
                 logger.error("error");
             }
+
+            @Override
+            public void onStallWarning(StallWarning arg0) {
+                logger.error("error");
+            }
         };
         twitterStream.addListener(statusListener);
         twitterStream.sample();
-
     }
 
     @Override
@@ -119,7 +126,6 @@ public class TwitterInputAdapter extends AdapterApp {
     }
 
     class Dequeuer implements Runnable {
-
         @Override
         public void run() {
             while (true) {
@@ -129,10 +135,8 @@ public class TwitterInputAdapter extends AdapterApp {
                     event.put("statusText", String.class, status.getText());
                     getRemoteStream().put(event);
                 } catch (Exception e) {
-
                 }
             }
-
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/276a4977/test-apps/twitter-counter/README.txt
----------------------------------------------------------------------
diff --git a/test-apps/twitter-counter/README.txt b/test-apps/twitter-counter/README.txt
index 5752b21..c6b514e 100644
--- a/test-apps/twitter-counter/README.txt
+++ b/test-apps/twitter-counter/README.txt
@@ -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
\ No newline at end of file
+Please follow the instructions in the S4 piper walkthrough on the documentation from the
website


Mime
View raw message