List of usage examples for twitter4j AsyncTwitter addListener
void addListener(TwitterListener listener);
From source file:com.marpies.ane.twitter.data.TwitterAPI.java
License:Apache License
public static void getAccessTokensForPIN(String PIN) { final AsyncTwitter twitter = getAsyncInstance(); twitter.addListener(new TwitterAdapter() { @Override//from w ww . j a v a 2 s .c o m public void gotOAuthAccessToken(AccessToken token) { AIR.log("Retrieved access tokens"); /* Store access tokens */ TwitterAPI.storeAccessTokens(token); AIR.dispatchEvent(AIRTwitterEvent.LOGIN_SUCCESS); } @Override public void onException(TwitterException te, TwitterMethod method) { if (method == TwitterMethod.OAUTH_ACCESS_TOKEN) { AIR.dispatchEvent(AIRTwitterEvent.LOGIN_ERROR, StringUtils.removeLineBreaks(te.getMessage())); } } }); twitter.getOAuthAccessTokenAsync(mRequestToken, PIN); }
From source file:com.marpies.ane.twitter.functions.DeleteStatusFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); long statusID = Long.valueOf(FREObjectUtils.getString(args[0])); mCallbackID = FREObjectUtils.getInt(args[1]); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken()); twitter.addListener(this); twitter.destroyStatus(statusID);/* w ww . j a va 2s.c om*/ return null; }
From source file:com.marpies.ane.twitter.functions.FollowUserFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); long userID = FREObjectUtils.getDouble(args[0]).longValue(); String screenName = (args[1] == null) ? null : FREObjectUtils.getString(args[1]); boolean enableNotifications = FREObjectUtils.getBoolean(args[2]); mCallbackID = FREObjectUtils.getInt(args[3]); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken()); twitter.addListener(this); if (screenName != null) { if (enableNotifications) { twitter.createFriendship(screenName, true); } else {//from w w w.j ava 2 s . c o m twitter.createFriendship(screenName); } } else { if (enableNotifications) { twitter.createFriendship(userID, true); } else { twitter.createFriendship(userID); } } return null; }
From source file:com.marpies.ane.twitter.functions.GetDirectMessagesFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); int count = FREObjectUtils.getInt(args[0]); long sinceID = (args[1] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[1])); long maxID = (args[2] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[2])); mCallbackID = FREObjectUtils.getInt(args[3]); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken()); twitter.addListener(this); Paging paging = getPaging(count, sinceID, maxID); if (paging != null) { twitter.getDirectMessages(paging); } else {/*w ww .j av a2 s . c o m*/ twitter.getDirectMessages(); } return null; }
From source file:com.marpies.ane.twitter.functions.GetFollowersFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); long cursor = FREObjectUtils.getDouble(args[0]).longValue(); long userID = FREObjectUtils.getDouble(args[1]).longValue(); String screenName = (args[2] == null) ? null : FREObjectUtils.getString(args[2]); mCallbackID = FREObjectUtils.getInt(args[3]); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken()); twitter.addListener(this); /* Query followers for screen name */ if (screenName != null) { twitter.getFollowersList(screenName, cursor); }/*from www .j a va2 s .co m*/ /* Or query for user ID */ else { /* If user ID was not provided then use the one of currently logged in user */ if (userID < 0) { userID = TwitterAPI.getLoggedInUser().getId(); } twitter.getFollowersList(userID, cursor); } return null; }
From source file:com.marpies.ane.twitter.functions.GetFriendsFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); long cursor = FREObjectUtils.getDouble(args[0]).longValue(); long userID = FREObjectUtils.getDouble(args[1]).longValue(); String screenName = (args[2] == null) ? null : FREObjectUtils.getString(args[2]); mCallbackID = FREObjectUtils.getInt(args[3]); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken()); twitter.addListener(this); /* Query followers for screen name */ if (screenName != null) { twitter.getFriendsList(screenName, cursor); }/*ww w .j av a 2 s . c om*/ /* Or query for user ID */ else { /* If user ID was not provided then use the one of currently logged in user */ if (userID < 0) { userID = TwitterAPI.getLoggedInUser().getId(); } twitter.getFriendsList(userID, cursor); } return null; }
From source file:com.marpies.ane.twitter.functions.GetHomeTimelineFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); int count = FREObjectUtils.getInt(args[0]); long sinceID = (args[1] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[1])); long maxID = (args[2] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[2])); mExcludeReplies = FREObjectUtils.getBoolean(args[3]); mCallbackID = FREObjectUtils.getInt(args[4]); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken()); twitter.addListener(this); Paging paging = getPaging(count, sinceID, maxID); if (paging != null) { twitter.getHomeTimeline(paging); } else {/*ww w. ja v a2 s. c o m*/ twitter.getHomeTimeline(); } return null; }
From source file:com.marpies.ane.twitter.functions.GetLikesFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); int count = FREObjectUtils.getInt(args[0]); long sinceID = (args[1] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[1])); long maxID = (args[2] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[2])); long userID = FREObjectUtils.getDouble(args[3]).longValue(); String screenName = (args[4] == null) ? null : FREObjectUtils.getString(args[4]); mCallbackID = FREObjectUtils.getInt(args[5]); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken()); twitter.addListener(this); /* If user ID was not provided then use the one of currently logged in user */ if (userID < 0) { userID = TwitterAPI.getLoggedInUser().getId(); }// ww w . ja va 2 s.com Paging paging = getPaging(count, sinceID, maxID); if (paging != null) { if (screenName != null) { twitter.getFavorites(screenName, paging); } else { twitter.getFavorites(userID, paging); } } else { if (screenName != null) { twitter.getFavorites(screenName); } else { twitter.getFavorites(userID); } } return null; }
From source file:com.marpies.ane.twitter.functions.GetLoggedInUserFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); mCallbackID = FREObjectUtils.getInt(args[0]); User user = TwitterAPI.getLoggedInUser(); /* Return cached object */ if (user != null) { try {/* w w w . j a v a 2 s .co m*/ dispatchUser(user); } catch (Exception e) { e.printStackTrace(); AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_ERROR, StringUtils.getEventErrorJSON(mCallbackID, e.getMessage())); } } /* Request user info */ else if (TwitterAPI.hasAccessTokens()) { AccessToken accessToken = TwitterAPI.getAccessToken(); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(accessToken); twitter.addListener(this); twitter.showUser(accessToken.getUserId()); } /* User not logged in, error */ else { AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_ERROR, StringUtils.getEventErrorJSON(mCallbackID, "User is not logged in.")); } return null; }
From source file:com.marpies.ane.twitter.functions.GetSentDirectMessagesFunction.java
License:Apache License
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); int count = FREObjectUtils.getInt(args[0]); long sinceID = (args[1] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[1])); long maxID = (args[2] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[2])); int page = FREObjectUtils.getInt(args[3]); mCallbackID = FREObjectUtils.getInt(args[4]); AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken()); twitter.addListener(this); Paging paging = getPaging(count, sinceID, maxID, page); if (paging != null) { twitter.getSentDirectMessages(paging); } else {/*from w w w . j av a 2s .com*/ twitter.getSentDirectMessages(); } return null; }