use of twitter4j.TwitterException in project twitter4j by yusuke.
the class ShowFriendship method main.
/**
* Usage: java twitter4j.examples.friendship.ShowFriendship [source screen name] [target screen name]
*
* @param args message
*/
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: java twitter4j.examples.friendship.ShowFriendship [source screen name] [target screen name]");
System.exit(-1);
}
try {
Twitter twitter = new TwitterFactory().getInstance();
Relationship relationship = twitter.showFriendship(args[0], args[1]);
System.out.println("isSourceBlockingTarget: " + relationship.isSourceBlockingTarget());
System.out.println("isSourceFollowedByTarget: " + relationship.isSourceFollowedByTarget());
System.out.println("isSourceFollowingByTarget: " + relationship.isSourceFollowingTarget());
System.out.println("isSourceNotificationsEnabled: " + relationship.isSourceNotificationsEnabled());
System.out.println("canSourceDm: " + relationship.canSourceDm());
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to show friendship: " + te.getMessage());
System.exit(-1);
}
}
use of twitter4j.TwitterException in project quorrabot by GloriousEggroll.
the class TwitterAPI method getlast.
public static String getlast() {
try {
List<Status> statuses = twitter.getUserTimeline();
Status status = statuses.get(0);
return status.getText();
} catch (TwitterException te) {
te.printStackTrace();
return null;
}
}
use of twitter4j.TwitterException in project asterixdb by apache.
the class TwitterPullRecordReader method next.
@Override
public IRawRecord<String> next() throws IOException, InterruptedException {
if (result == null || nextTweetIndex >= result.getTweets().size()) {
Thread.sleep(1000 * requestInterval);
query.setSinceId(lastTweetIdReceived);
try {
result = twitter.search(query);
} catch (TwitterException e) {
throw new HyracksDataException(e);
}
nextTweetIndex = 0;
}
if (result != null && !result.getTweets().isEmpty()) {
List<Status> tw = result.getTweets();
Status tweet = tw.get(nextTweetIndex++);
if (lastTweetIdReceived < tweet.getId()) {
lastTweetIdReceived = tweet.getId();
}
// transform tweet obj to json
String jsonTweet = TwitterObjectFactory.getRawJSON(tweet);
record.set(jsonTweet);
return record;
} else {
return null;
}
}
use of twitter4j.TwitterException 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.TwitterException in project android-priority-jobqueue by path.
the class PostTweetJob method onAdded.
@Override
public void onAdded() {
// job has been secured to disk, add item to database
try {
Tweet tweet = new Tweet(localId, null, text, TwitterController.getInstance().getUserId(), null, new Date(System.currentTimeMillis()));
TweetModel.getInstance().insertOrReplace(tweet);
EventBus.getDefault().post(new PostingTweetEvent(tweet));
} catch (TwitterException exception) {
// if we cannot get user id, we won't add it locally for now.
}
}
Aggregations