use of twitter4j.TwitterFactory in project Talon-for-Twitter by klinker24.
the class Utils method getTwitter.
public static Twitter getTwitter(Context context) {
AppSettings settings = AppSettings.getInstance(context);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey(AppSettings.TWITTER_CONSUMER_KEY).setOAuthConsumerSecret(AppSettings.TWITTER_CONSUMER_SECRET).setOAuthAccessToken(settings.authenticationToken).setOAuthAccessTokenSecret(settings.authenticationTokenSecret);
cb.setTweetModeExtended(true);
TwitterFactory tf = new TwitterFactory(cb.build());
return tf.getInstance();
}
use of twitter4j.TwitterFactory in project Talon-for-Twitter by klinker24.
the class Utils method getSecondTwitter.
public static Twitter getSecondTwitter(Context context) {
AppSettings settings = AppSettings.getInstance(context);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey(AppSettings.TWITTER_CONSUMER_KEY).setOAuthConsumerSecret(AppSettings.TWITTER_CONSUMER_SECRET).setOAuthAccessToken(settings.secondAuthToken).setOAuthAccessTokenSecret(settings.secondAuthTokenSecret);
TwitterFactory tf = new TwitterFactory(cb.build());
return tf.getInstance();
}
use of twitter4j.TwitterFactory in project mobile-android by photo.
the class TwitterUtils method instantiateTwitter.
/**
* Instantiate the twitter api instance
*
* @param context
* @return
*/
static Twitter instantiateTwitter(Context context) {
Twitter twitter = null;
// Get Access Token and persist it
AccessToken a = TwitterUtils.getAccessToken(context);
if (a != null) {
// initialize Twitter4J
twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(getConsumerKey(context), getConsumerSecret(context));
twitter.setOAuthAccessToken(a);
}
return twitter;
}
use of twitter4j.TwitterFactory in project twitter-2-weibo by rjyo.
the class UserServlet method handleRequest.
@Override
protected Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context ctx) {
HttpServletRouter r = new HttpServletRouter(request);
r.setPattern("/:id");
HttpSession session = request.getSession(false);
DBHelper helper = (DBHelper) request.getAttribute(Keys.REQUEST_DB_HELPER);
// Service limit
String uId = r.get(":id");
if (!helper.isUser(uId) && helper.getUserCount() > 50) {
return getTemplate("full.vm");
}
T2WUser user = helper.findOneByUser(uId);
if (r.has(":id")) {
log.info("Displaying user info for @" + uId);
ctx.put("user_id", uId);
ctx.put("user", helper.findOneByUser(uId));
try {
User weiboUser = (User) session.getAttribute(Keys.SESSION_WEIBO_USER);
if (weiboUser == null) {
Users um = new Users();
weiboUser = um.showUserById(user.getWeiboUserId());
session.setAttribute(Keys.SESSION_WEIBO_USER, weiboUser);
}
ctx.put("weibo_user", weiboUser.getScreenName());
ctx.put("weibo_user_image", weiboUser.getProfileImageURL().toString());
ctx.put("weibo_login", 1);
// save weiboUser ID mapping
helper.setWeiboId(user.getUserId(), weiboUser.getScreenName());
} catch (Exception e) {
// 401 = not logged in
if (e instanceof WeiboException && ((WeiboException) e).getStatusCode() != 401) {
e.printStackTrace();
}
}
try {
twitter4j.User twitterUser = (twitter4j.User) session.getAttribute(Keys.SESSION_TWITTER_USER);
if (twitterUser == null) {
TwitterFactory factory = new TwitterFactory();
Twitter t = factory.getInstance();
t.setOAuthAccessToken(new AccessToken(user.getTwitterToken(), user.getTwitterTokenSecret()));
twitterUser = t.verifyCredentials();
session.setAttribute(Keys.SESSION_TWITTER_USER, twitterUser);
}
ctx.put("twitter_user", twitterUser.getScreenName());
ctx.put("twitter_user_image", twitterUser.getProfileImageURL().toString());
ctx.put("twitter_login", 1);
} catch (Exception e) {
// 401 = not logged in
if (e instanceof TwitterException && ((TwitterException) e).getStatusCode() != 401) {
e.printStackTrace();
}
}
}
Object message = session.getAttribute(Keys.SESSION_MESSAGE);
if (message != null) {
ctx.put("message", message);
session.removeAttribute(Keys.SESSION_MESSAGE);
}
Object prompt = session.getAttribute(Keys.SESSION_PROMPT_TWEET);
if (prompt != null) {
ctx.put("prompt", prompt);
session.removeAttribute(Keys.SESSION_PROMPT_TWEET);
}
return getTemplate("user.vm");
}
use of twitter4j.TwitterFactory in project twitter4j by yusuke.
the class GetRateLimitStatus method main.
/**
* Usage: java twitter4j.examples.account.GetRateLimitStatus
*
* @param args message
*/
public static void main(String[] args) {
try {
Twitter twitter = new TwitterFactory().getInstance();
Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus();
for (String endpoint : rateLimitStatus.keySet()) {
RateLimitStatus status = rateLimitStatus.get(endpoint);
System.out.println("Endpoint: " + endpoint);
System.out.println(" Limit: " + status.getLimit());
System.out.println(" Remaining: " + status.getRemaining());
System.out.println(" ResetTimeInSeconds: " + status.getResetTimeInSeconds());
System.out.println(" SecondsUntilReset: " + status.getSecondsUntilReset());
}
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get rate limit status: " + te.getMessage());
System.exit(-1);
}
}
Aggregations