summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-04-30 23:32:01 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-04-30 23:32:01 +0200
commit7c2d2b66a21b9a0889e78cf5ff0982245c47bb69 (patch)
tree97a860ebf5f2c223ceb7db2b2059817f3279773c
parentc72c5c10047304ba6961211307a996c9e4be6994 (diff)
downloadTwitterDataAnalytics-7c2d2b66a21b9a0889e78cf5ff0982245c47bb69.tar.gz
TwitterApi: retry asking for PIN if missing
Also provide access to requester for stream thingey.
-rw-r--r--src/mining/TwitterApi.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/mining/TwitterApi.java b/src/mining/TwitterApi.java
index 7f431c3..372aade 100644
--- a/src/mining/TwitterApi.java
+++ b/src/mining/TwitterApi.java
@@ -93,9 +93,22 @@ public class TwitterApi {
throw new IOException("Unable to retrieve an access token");
}
String authUrl = oreq.getAuthURL();
- oreq.supplyPINForTokens(ps.requestPin(authUrl));
+ for (int i = 0; i < 5; ++i) {
+ try {
+ String pin = ps.requestPin(authUrl);
+ // stop asking if an empty PIN was supplied
+ if (!pin.isEmpty()) {
+ oreq.supplyPINForTokens(pin);
+ }
+ break;
+ } catch (IOException ex) {
+ System.err.println("Trying again, PIN rejected: " + ex);
+ }
+ }
secrets = oreq.getSecrets();
- assert secrets != null : "PIN accepted, but no access tokens?";
+ if (secrets == null) {
+ throw new IOException("Unable to get access tokens");
+ }
cfg.setProperty(CFG_OAUTH_TOKEN, secrets.getToken());
cfg.setProperty(CFG_OAUTH_SECRET, secrets.getSecret());
cfg.save();
@@ -130,6 +143,13 @@ public class TwitterApi {
return new Builder(resource);
}
+ /**
+ * @return The requester instance associated with this.
+ */
+ public Requester getRequester() {
+ return requester;
+ }
+
public class Builder {
private final String resource;