use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class RetweetersFragment method findUsers.
@Override
protected List<User> findUsers(long tweetId) {
Twitter twitter = Utils.getTwitter(context, settings);
List<User> users = new ArrayList<User>();
try {
Status stat = twitter.showStatus(tweetId);
if (stat.isRetweet()) {
tweetId = stat.getRetweetedStatus().getId();
}
// can get 100 retweeters is all
ResponseList<Status> lists = twitter.getRetweets(tweetId);
for (Status status : lists) {
users.add(status.getUser());
}
} catch (Exception e) {
}
return users;
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class ProfilePicturesFragment method doSearch.
public void doSearch() {
spinner.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
ResponseList<Status> result;
try {
result = twitter.getUserTimeline(screenName, paging);
} catch (OutOfMemoryError e) {
return;
}
tweets.clear();
for (twitter4j.Status status : result) {
tweets.add(status);
}
if (result.size() > 17) {
hasMore = true;
} else {
hasMore = false;
}
for (Status s : tweets) {
String[] links = TweetLinkUtils.getLinksInStatus(s);
if (!links[1].equals("")) {
pics.add(links[1]);
tweetsWithPics.add(s);
}
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int numColumns;
int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
numColumns = 5;
} else {
numColumns = 3;
}
adapter = new PicturesGridAdapter(context, pics, tweetsWithPics, width / numColumns);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
canRefresh = true;
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
canRefresh = false;
}
});
}
}
}).start();
}
use of twitter4j.Twitter in project AndroidSDK-RecipeBook by gabu.
the class Auth method onOKButton.
// OKボタンが押されたら呼び出される
public void onOKButton(View view) {
// 入力されたユーザIDとパスワードを取得
String userID = ((EditText) findViewById(R.id.user_id)).getText().toString();
String password = ((EditText) findViewById(R.id.password)).getText().toString();
// とりあえずユーザIDとパスワードでTwitterインスタンスを生成
Twitter twitter = new TwitterFactory().getInstance(userID, password);
try {
// AccessTokenを取得
AccessToken accessToken = twitter.getOAuthAccessToken();
// tokenとtokenSecretを取得
String token = accessToken.getToken();
String tokenSecret = accessToken.getTokenSecret();
// プリファレンスのEditorを取得
Editor e = getSharedPreferences(Recipe102.PREF_NAME, MODE_PRIVATE).edit();
// tokenとtokenSecretを書き込んで
e.putString(Recipe102.PREF_KEY_TOKEN, token);
e.putString(Recipe102.PREF_KEY_TOKEN_SECRET, tokenSecret);
// 保存!
e.commit();
// Authアクティビティを終了
finish();
} catch (TwitterException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "ユーザIDかパスワードが間違っています。", Toast.LENGTH_SHORT).show();
}
}
use of twitter4j.Twitter in project AndroidSDK-RecipeBook by gabu.
the class Recipe102 method onResume.
public void onResume() {
super.onResume();
// プリファレンスを取得
SharedPreferences sp = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
// tokenとtokenSecretを取得
String token = sp.getString(PREF_KEY_TOKEN, "");
String tokenSecret = sp.getString(PREF_KEY_TOKEN_SECRET, "");
// 値がなければAuthアクティビティを起動
if ("".equals(token) || "".equals(tokenSecret)) {
Intent intent = new Intent(this, Auth.class);
startActivity(intent);
}
// twitter4jのConfigurationを取得
Configuration conf = ConfigurationContext.getInstance();
// AccessTokenを生成
AccessToken accessToken = new AccessToken(token, tokenSecret);
// OAuthAuthorizationを生成
Authorization auth = new OAuthAuthorization(conf, conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret(), accessToken);
// OAuthAuthorizationを使ってTwitterインスタンスを生成
Twitter twitter = new TwitterFactory().getInstance(auth);
try {
// とりあえずテストのためTLをログ出力
ResponseList<Status> statuses = twitter.getHomeTimeline();
for (Status status : statuses) {
Log.d(TAG, status.getUser().getName() + ":" + status.getText());
}
} catch (TwitterException e) {
e.printStackTrace();
}
}
use of twitter4j.Twitter in project camel by apache.
the class SearchConsumer method search.
private List<Exchange> search(Query query) throws TwitterException {
Integer numberOfPages = 1;
if (ObjectHelper.isNotEmpty(endpoint.getProperties().getLang())) {
query.setLang(endpoint.getProperties().getLang());
}
if (ObjectHelper.isNotEmpty(endpoint.getProperties().getCount())) {
query.setCount(endpoint.getProperties().getCount());
}
if (ObjectHelper.isNotEmpty(endpoint.getProperties().getNumberOfPages())) {
numberOfPages = endpoint.getProperties().getNumberOfPages();
}
if (ObjectHelper.isNotEmpty(endpoint.getProperties().getLatitude()) && ObjectHelper.isNotEmpty(endpoint.getProperties().getLongitude()) && ObjectHelper.isNotEmpty(endpoint.getProperties().getRadius())) {
GeoLocation location = new GeoLocation(endpoint.getProperties().getLatitude(), endpoint.getProperties().getLongitude());
query.setGeoCode(location, endpoint.getProperties().getRadius(), Unit.valueOf(endpoint.getProperties().getDistanceMetric()));
LOG.debug("Searching with additional geolocation parameters.");
}
LOG.debug("Searching with {} pages.", numberOfPages);
Twitter twitter = getTwitter();
QueryResult qr = twitter.search(query);
List<Status> tweets = qr.getTweets();
for (int i = 1; i < numberOfPages; i++) {
if (!qr.hasNext()) {
break;
}
qr = twitter.search(qr.nextQuery());
tweets.addAll(qr.getTweets());
}
if (endpoint.getProperties().isFilterOld()) {
for (int i = 0; i < tweets.size(); i++) {
setLastIdIfGreater(tweets.get(i).getId());
}
}
return TwitterEventType.STATUS.createExchangeList(endpoint, tweets);
}
Aggregations