summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice Laveaux <m.laveaux@student.tue.nl>2014-04-23 16:08:08 +0200
committerMaurice Laveaux <m.laveaux@student.tue.nl>2014-04-23 16:08:08 +0200
commitab095e0ecbe63dc19f4de69872b14aee921bba6b (patch)
tree06700cb7a9f62a55f439f14d21584cc8356489a7
parent14d7547cd31c5be878e377a4a5370f604c8d59d4 (diff)
downloadTwitterDataAnalytics-ab095e0ecbe63dc19f4de69872b14aee921bba6b.tar.gz
Renamed OAuthUtils to Configuration class.
-rw-r--r--src/Chapter2/openauthentication/OAuthExample.java10
-rw-r--r--src/Chapter2/restapi/RESTApiExample.java2
-rw-r--r--src/Chapter2/restapi/RESTSearchExample.java4
-rw-r--r--src/Chapter2/streamingapi/StreamingApiExample.java4
-rw-r--r--src/utils/Configuration.java14
-rw-r--r--src/utils/OAuthUtils.java21
6 files changed, 24 insertions, 31 deletions
diff --git a/src/Chapter2/openauthentication/OAuthExample.java b/src/Chapter2/openauthentication/OAuthExample.java
index 9b2ec7a..34ca3a1 100644
--- a/src/Chapter2/openauthentication/OAuthExample.java
+++ b/src/Chapter2/openauthentication/OAuthExample.java
@@ -16,7 +16,7 @@ import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;
-import utils.OAuthUtils;
+import utils.Configuration;
public class OAuthExample
{
@@ -24,18 +24,18 @@ public class OAuthExample
{
try {
//consumer key for Twitter Data Analytics application
- if(OAuthUtils.CONSUMER_KEY.isEmpty())
+ if(Configuration.CONSUMER_KEY.isEmpty())
{
System.out.println("Register an application and copy the consumer key into the configuration file.");
return null;
}
- if(OAuthUtils.CONSUMER_SECRET.isEmpty())
+ if(Configuration.CONSUMER_SECRET.isEmpty())
{
System.out.println("Register an application and copy the consumer secret into the configuration file.");
return null;
}
- OAuthConsumer consumer = new CommonsHttpOAuthConsumer(OAuthUtils.CONSUMER_KEY,OAuthUtils.CONSUMER_SECRET);
- OAuthProvider provider = new DefaultOAuthProvider(OAuthUtils.REQUEST_TOKEN_URL, OAuthUtils.ACCESS_TOKEN_URL, OAuthUtils.AUTHORIZE_URL);
+ OAuthConsumer consumer = new CommonsHttpOAuthConsumer(Configuration.CONSUMER_KEY,Configuration.CONSUMER_SECRET);
+ OAuthProvider provider = new DefaultOAuthProvider(Configuration.REQUEST_TOKEN_URL, Configuration.ACCESS_TOKEN_URL, Configuration.AUTHORIZE_URL);
String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
System.out.println("Now visit:\n" + authUrl + "\n and grant this app authorization");
System.out.println("Enter the PIN code and hit ENTER when you're done:");
diff --git a/src/Chapter2/restapi/RESTApiExample.java b/src/Chapter2/restapi/RESTApiExample.java
index 9ceb88b..3d6074b 100644
--- a/src/Chapter2/restapi/RESTApiExample.java
+++ b/src/Chapter2/restapi/RESTApiExample.java
@@ -48,7 +48,7 @@ public class RESTApiExample
*/
public OAuthConsumer GetConsumer()
{
- OAuthConsumer consumer = new DefaultOAuthConsumer(utils.OAuthUtils.CONSUMER_KEY,utils.OAuthUtils.CONSUMER_SECRET);
+ OAuthConsumer consumer = new DefaultOAuthConsumer(utils.Configuration.CONSUMER_KEY,utils.Configuration.CONSUMER_SECRET);
consumer.setTokenWithSecret(OAuthTokens.getAccessToken(),OAuthTokens.getAccessSecret());
return consumer;
}
diff --git a/src/Chapter2/restapi/RESTSearchExample.java b/src/Chapter2/restapi/RESTSearchExample.java
index 510661c..e9a5dd7 100644
--- a/src/Chapter2/restapi/RESTSearchExample.java
+++ b/src/Chapter2/restapi/RESTSearchExample.java
@@ -43,7 +43,7 @@ public class RESTSearchExample
*/
public OAuthConsumer GetConsumer()
{
- OAuthConsumer consumer = new DefaultOAuthConsumer(utils.OAuthUtils.CONSUMER_KEY,utils.OAuthUtils.CONSUMER_SECRET);
+ OAuthConsumer consumer = new DefaultOAuthConsumer(utils.Configuration.CONSUMER_KEY,utils.Configuration.CONSUMER_SECRET);
consumer.setTokenWithSecret(OAuthTokens.getAccessToken(), OAuthTokens.getAccessSecret());
return consumer;
}
@@ -138,7 +138,7 @@ public class RESTSearchExample
URL url = new URL("https://api.twitter.com/1.1/application/rate_limit_status.json");
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setReadTimeout(5000);
- OAuthConsumer consumer = new DefaultOAuthConsumer(utils.OAuthUtils.CONSUMER_KEY,utils.OAuthUtils.CONSUMER_SECRET);
+ OAuthConsumer consumer = new DefaultOAuthConsumer(utils.Configuration.CONSUMER_KEY,utils.Configuration.CONSUMER_SECRET);
consumer.setTokenWithSecret(OAuthTokens.getAccessToken(), OAuthTokens.getAccessSecret());
consumer.sign(huc);
huc.connect();
diff --git a/src/Chapter2/streamingapi/StreamingApiExample.java b/src/Chapter2/streamingapi/StreamingApiExample.java
index 8abfff4..61a9cc0 100644
--- a/src/Chapter2/streamingapi/StreamingApiExample.java
+++ b/src/Chapter2/streamingapi/StreamingApiExample.java
@@ -38,7 +38,7 @@ import org.apache.http.params.CoreConnectionPNames;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
-import utils.OAuthUtils;
+import utils.Configuration;
public class StreamingApiExample
{
@@ -73,7 +73,7 @@ public class StreamingApiExample
HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(90000));
//Step 1: Initialize OAuth Consumer
- OAuthConsumer consumer = new CommonsHttpOAuthConsumer(OAuthUtils.CONSUMER_KEY,OAuthUtils.CONSUMER_SECRET);
+ OAuthConsumer consumer = new CommonsHttpOAuthConsumer(Configuration.CONSUMER_KEY,Configuration.CONSUMER_SECRET);
consumer.setTokenWithSecret(OAuthToken.getAccessToken(),OAuthToken.getAccessSecret());
//Step 2: Create a new HTTP POST request and set parameters
HttpPost httppost = new HttpPost(baseUrl);
diff --git a/src/utils/Configuration.java b/src/utils/Configuration.java
new file mode 100644
index 0000000..0595a86
--- /dev/null
+++ b/src/utils/Configuration.java
@@ -0,0 +1,14 @@
+package utils;
+
+// This class contains important values for the open authentication.
+public class Configuration
+{
+ // The constumer secret value obtained from twitter.com
+ public static final String CONSUMER_SECRET = "0aQLFiAwAgPHOYt6tziWoDftayQR7n3cUzMbGlhiNqsNNylLu4";
+ // The constumer public value obtained from twitter.com
+ public static final String CONSUMER_KEY = "1Qc8Y5kmWIZy13m0hVxgGJOPt";
+
+ public static final String REQUEST_TOKEN_URL = "https://twitter.com/oauth/request_token";
+ public static final String AUTHORIZE_URL = "https://twitter.com/oauth/authorize";
+ public static final String ACCESS_TOKEN_URL = "https://twitter.com/oauth/access_token";
+}
diff --git a/src/utils/OAuthUtils.java b/src/utils/OAuthUtils.java
deleted file mode 100644
index 3cd5703..0000000
--- a/src/utils/OAuthUtils.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/* TweetTracker. Copyright (c) Arizona Board of Regents on behalf of Arizona State University
- * @author shamanth
- */
-package utils;
-
-public class OAuthUtils
-{
- //Please replace the Consumer key and secret to the one representing your application.
- public static final String CONSUMER_SECRET = "PPCTObQGbGm1gkNvdJiTPKhoTksG787RTBwardkbM";
- public static final String CONSUMER_KEY = "L8CRRCUoRl3xcZ9bdrfUw";
- public static final String REQUEST_TOKEN_URL = "https://twitter.com/oauth/request_token";
- public static final String AUTHORIZE_URL = "https://twitter.com/oauth/authorize";
- public static final String ACCESS_TOKEN_URL = "https://twitter.com/oauth/access_token";
-
-
- //Use a JFIG file for all the configurations
- public void ReadApplicationIdentity()
- {
-
- }
-}