List of usage examples for twitter4j TwitterException TwitterException
public TwitterException(Exception cause)
From source file:mx.bigdata.t4j.TwitterStreamImpl.java
License:Apache License
/** * {@inheritDoc}//from w ww .ja v a 2s . com */ public StatusStream getUserStream(String[] track) throws TwitterException { ensureAuthorizationEnabled(); try { List<HttpParameter> params = new ArrayList<HttpParameter>(); if (conf.isUserStreamRepliesAllEnabled()) { params.add(new HttpParameter("replies", "all")); } if (null != track) { params.add(new HttpParameter("track", T4JInternalStringUtil.join(track))); } return new StatusStreamImpl(http.post(conf.getUserStreamBaseURL() + "user.json", params.toArray(new HttpParameter[params.size()]), auth)); } catch (IOException e) { throw new TwitterException(e); } }
From source file:mx.bigdata.t4j.TwitterStreamImpl.java
License:Apache License
/** * {@inheritDoc}/* w ww . j a v a2s . c o m*/ */ public TwitterStreamConsumer site(final boolean withFollowings, final long[] follow) { ensureOAuthEnabled(); ensureListenerIsSet(); return startHandler(new StatusStreamProvider() { public StatusStream getStream() throws TwitterException { try { return new StatusStreamImpl(getSiteStream(withFollowings, follow)); } catch (IOException e) { throw new TwitterException(e); } } }, streamListener); }
From source file:mx.bigdata.t4j.TwitterStreamImpl.java
License:Apache License
StatusStream getFilterStream(FilterQuery query) throws TwitterException { ensureAuthorizationEnabled();/*from w ww . j a va2 s . c o m*/ try { List<HttpParameter> params = new ArrayList(Arrays.asList(query.asHttpParameterArray())); params.add(new HttpParameter("delimited", "length")); return new StatusStreamImpl(http.post(conf.getStreamBaseURL() + "statuses/filter.json", params.toArray(new HttpParameter[0]), auth)); } catch (IOException e) { throw new TwitterException(e); } }
From source file:org.getlantern.firetweet.extension.streaming.util.OkHttpClientImpl.java
License:Open Source License
@Override public HttpResponse request(HttpRequest req) throws TwitterException { final Builder builder = new Builder(); for (Entry<String, List<String>> headerEntry : req.getRequestHeaders().entrySet()) { final String name = headerEntry.getKey(); for (String value : headerEntry.getValue()) { builder.addHeader(name, value); }/*from w w w . ja va 2s . c o m*/ } final Authorization authorization = req.getAuthorization(); if (authorization != null) { final String authHeader = authorization.getAuthorizationHeader(req); if (authHeader != null) { builder.header("Authorization", authHeader); } } try { setupRequestBuilder(builder, req); final Response response = client.newCall(builder.build()).execute(); return new OkHttpResponse(conf, null, response); } catch (IOException e) { throw new TwitterException(e); } }
From source file:org.getlantern.firetweet.loader.support.MediaTimelineLoader.java
License:Open Source License
@NonNull @Override/* w ww .j a v a2s . c o m*/ protected ResponseList<Status> getStatuses(@NonNull final Twitter twitter, final Paging paging) throws TwitterException { if (mUserId != -1) return twitter.getMediaTimeline(mUserId, paging); else if (mUserScreenName != null) return twitter.getMediaTimeline(mUserScreenName, paging); throw new TwitterException("Wrong user"); }
From source file:org.getlantern.firetweet.loader.support.TwitterAPIStatusesLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w.j av a 2 s.co m*/ public final List<ParcelableStatus> loadInBackground() { final File serializationFile = getSerializationFile(); final List<ParcelableStatus> data = getData(); if (isFirstLoad() && getTabPosition() >= 0 && serializationFile != null) { final List<ParcelableStatus> cached = getCachedData(serializationFile); if (cached != null) { data.addAll(cached); if (mComparator != null) { Collections.sort(data, mComparator); } else { Collections.sort(data); } return new CopyOnWriteArrayList<>(data); } } if (!isFromUser()) return data; final List<Status> statuses; final boolean truncated; final Context context = getContext(); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); try { final Paging paging = new Paging(); paging.setCount(loadItemLimit); if (mMaxId > 0) { paging.setMaxId(mMaxId); } if (mSinceId > 0) { paging.setSinceId(mSinceId - 1); } statuses = new ArrayList<>(); final Twitter twitter = getTwitter(); if (twitter == null) { throw new TwitterException("Account is null"); } truncated = truncateStatuses(getStatuses(twitter, paging), statuses, mSinceId); } catch (final TwitterException e) { // mHandler.post(new ShowErrorRunnable(e)); Log.w(LOGTAG, e); return new CopyOnWriteArrayList<>(data); } final long minStatusId = statuses.isEmpty() ? -1 : Collections.min(statuses).getId(); final boolean insertGap = minStatusId > 0 && statuses.size() > 1 && !data.isEmpty() && !truncated; for (final Status status : statuses) { final long id = status.getId(); final boolean deleted = deleteStatus(data, id); data.add(new ParcelableStatus(status, mAccountId, minStatusId == id && insertGap && !deleted)); } final ParcelableStatus[] array = data.toArray(new ParcelableStatus[data.size()]); for (int i = 0, size = array.length; i < size; i++) { final ParcelableStatus status = array[i]; if (shouldFilterStatus(mDatabase, status) && !status.is_gap && i != size - 1) { deleteStatus(data, status.id); } } if (mComparator != null) { Collections.sort(data, mComparator); } else { Collections.sort(data); } saveCachedData(serializationFile, data); return new CopyOnWriteArrayList<>(data); }
From source file:org.getlantern.firetweet.loader.support.UserListTimelineLoader.java
License:Open Source License
@NonNull @Override/*from w w w . ja v a 2 s .c o m*/ protected ResponseList<Status> getStatuses(@NonNull final Twitter twitter, final Paging paging) throws TwitterException { if (mListId > 0) return twitter.getUserListStatuses(mListId, paging); else if (mListName == null) throw new TwitterException("No list name or id given"); else if (mUserId > 0) return twitter.getUserListStatuses(mListName.replace(' ', '-'), mUserId, paging); else if (mScreenName != null) return twitter.getUserListStatuses(mListName.replace(' ', '-'), mScreenName, paging); throw new TwitterException("User id or screen name is required for list name"); }
From source file:org.getlantern.firetweet.util.net.OkHttpClientImpl.java
License:Open Source License
@Override public HttpResponse request(HttpRequest req) throws TwitterException { final Builder builder = new Builder(); for (Entry<String, List<String>> headerEntry : req.getRequestHeaders().entrySet()) { final String name = headerEntry.getKey(); for (String value : headerEntry.getValue()) { builder.addHeader(name, value); }//from w ww . j a va 2 s .co m } final Authorization authorization = req.getAuthorization(); if (authorization != null) { final String authHeader = authorization.getAuthorizationHeader(req); if (authHeader != null) { builder.header("Authorization", authHeader); } } Response response = null; try { setupRequestBuilder(builder, req); response = client.newCall(builder.build()).execute(); return new OkHttpResponse(conf, null, response); } catch (IOException e) { Crashlytics.logException(e); throw new TwitterException(e); } }
From source file:org.getlantern.firetweet.util.TwitterWrapper.java
License:Open Source License
@NonNull public static User showUserAlternative(final Twitter twitter, final long id, final String screenName) throws TwitterException { final String searchScreenName; if (screenName != null) { searchScreenName = screenName;//from w ww.j ava 2 s . c o m } else if (id != -1) { searchScreenName = twitter.showFriendship(twitter.getId(), id).getTargetUserScreenName(); } else throw new IllegalArgumentException(); final Paging paging = new Paging(); paging.count(1); if (id != -1) { final ResponseList<Status> timeline = twitter.getUserTimeline(id, paging); for (final Status status : timeline) { final User user = status.getUser(); if (user.getId() == id) return user; } } else { final ResponseList<Status> timeline = twitter.getUserTimeline(screenName, paging); for (final Status status : timeline) { final User user = status.getUser(); if (searchScreenName.equalsIgnoreCase(user.getScreenName())) return user; } } for (final User user : twitter.searchUsers(searchScreenName, 1)) { if (user.getId() == id || searchScreenName.equalsIgnoreCase(user.getScreenName())) return user; } throw new TwitterException("can't find user"); }
From source file:org.getlantern.firetweet.util.Utils.java
License:Open Source License
@NonNull public static ParcelableStatus findStatus(final Context context, final long accountId, final long statusId) throws TwitterException { if (context == null) throw new NullPointerException(); final ParcelableStatus cached = findStatusInDatabases(context, accountId, statusId); if (cached != null) return cached; final Twitter twitter = getTwitterInstance(context, accountId, true); if (twitter == null) throw new TwitterException("Account does not exist"); final Status status = twitter.showStatus(statusId); final String where = Expression.and(Expression.equals(Statuses.ACCOUNT_ID, accountId), Expression.equals(Statuses.STATUS_ID, statusId)).getSQL(); final ContentResolver resolver = context.getContentResolver(); resolver.delete(CachedStatuses.CONTENT_URI, where, null); resolver.insert(CachedStatuses.CONTENT_URI, ContentValuesCreator.createStatus(status, accountId)); return new ParcelableStatus(status, accountId, false); }