List of usage examples for twitter4j Twitter getOAuthAccessToken
AccessToken getOAuthAccessToken() throws TwitterException;
From source file:com.vti.managers.AccountManager.java
License:Apache License
/** * //from w ww . j a v a2 s . c o m * @return OAuth OAuthTokens from save Accounts */ public AccessToken getAuthTokens() { if (tf != null) { Twitter twitter = tf.getInstance(); try { return twitter.getOAuthAccessToken(); } catch (TwitterException e) { Log.d(TAG, Log.stack2string(e)); return null; } } else return null; }
From source file:de.vanita5.twittnuker.util.shortener.TweetShortenerUtils.java
License:Open Source License
/** * Gets the header to verify the user on Twitter * twitter4j/*from www . j ava2 s.c o m*/ * @param twitter Coming from Twitter.getInstance() * @return String of the header to be used with X-Verify-Credentials-Authorization */ public static String getHeader(Twitter twitter) { try { final long timestamp = System.currentTimeMillis() / 1000; Random rand = new Random(); final long nonce = timestamp + rand.nextInt(); final List<HttpParameter> oauthHeaderParams = new ArrayList<HttpParameter>(5); oauthHeaderParams.add(new HttpParameter("oauth_consumer_key", TWITTER_CONSUMER_KEY_2)); oauthHeaderParams.add(new HttpParameter("oauth_signature_method", "HMAC-SHA1")); oauthHeaderParams.add(new HttpParameter("oauth_timestamp", timestamp)); oauthHeaderParams.add(new HttpParameter("oauth_nonce", nonce)); oauthHeaderParams.add(new HttpParameter("oauth_version", "1.1")); if (twitter.getOAuthAccessToken() != null) { oauthHeaderParams.add(new HttpParameter("oauth_token", twitter.getOAuthAccessToken().getToken())); } final List<HttpParameter> signatureBaseParams = new ArrayList<HttpParameter>(oauthHeaderParams.size()); signatureBaseParams.addAll(oauthHeaderParams); parseGetParameters(OAUTH_SERVICE_PROVIDER, signatureBaseParams); final StringBuffer base = new StringBuffer("GET").append("&") .append(HttpParameter.encode(constructRequestURL(OAUTH_SERVICE_PROVIDER))).append("&"); base.append(HttpParameter.encode(normalizeRequestParameters(signatureBaseParams))); final String oauthBaseString = base.toString(); final String signature = generateSignature(oauthBaseString, twitter.getOAuthAccessToken()); oauthHeaderParams.add(new HttpParameter("oauth_signature", signature)); return "OAuth realm=\"http://api.twitter.com/\"," + OAuthAuthorization.encodeParameters(oauthHeaderParams, ",", true); } catch (TwitterException e) { e.printStackTrace(); } return null; }
From source file:org.taverna.server.master.notification.TwitterDispatcher.java
private Twitter getTwitter(String key, String secret) throws Exception { if (key.isEmpty() || secret.isEmpty()) throw new NoCredentialsException(); Properties p = getConfig();//from w ww. j a v a 2 s . c o m p.setProperty(OAUTH_CONSUMER_KEY, key); p.setProperty(OAUTH_CONSUMER_SECRET, secret); Configuration config = new PropertyConfiguration(p); TwitterFactory factory = new TwitterFactory(config); Twitter t = factory.getInstance(AuthorizationFactory.getInstance(config)); // Verify that we can connect! t.getOAuthAccessToken(); return t; }