use of twitter4j.TwitterException in project Talon-for-Twitter by klinker24.
the class DirectMessageRefreshService method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
Context context = getApplicationContext();
AppSettings settings = AppSettings.getInstance(context);
// if they have mobile data on and don't want to sync over mobile data
if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
return;
}
boolean update = false;
int numberNew = 0;
try {
Twitter twitter = Utils.getTwitter(context, settings);
int currentAccount = sharedPrefs.getInt("current_account", 1);
User user = twitter.verifyCredentials();
long lastId = sharedPrefs.getLong("last_direct_message_id_" + currentAccount, 0);
Paging paging;
if (lastId != 0) {
paging = new Paging(1).sinceId(lastId);
} else {
paging = new Paging(1, 500);
}
List<DirectMessage> dm = twitter.getDirectMessages(paging);
List<DirectMessage> sent = twitter.getSentDirectMessages(paging);
if (dm.size() != 0) {
sharedPrefs.edit().putLong("last_direct_message_id_" + currentAccount, dm.get(0).getId()).commit();
numberNew = dm.size();
} else {
numberNew = 0;
}
DMDataSource dataSource = DMDataSource.getInstance(context);
int inserted = 0;
for (DirectMessage directMessage : dm) {
try {
dataSource.createDirectMessage(directMessage, currentAccount);
} catch (Exception e) {
dataSource = DMDataSource.getInstance(context);
dataSource.createDirectMessage(directMessage, currentAccount);
}
inserted++;
}
for (DirectMessage directMessage : sent) {
try {
dataSource.createDirectMessage(directMessage, currentAccount);
} catch (Exception e) {
dataSource = DMDataSource.getInstance(context);
dataSource.createDirectMessage(directMessage, currentAccount);
}
}
sharedPrefs.edit().putBoolean("refresh_me", true).commit();
sharedPrefs.edit().putBoolean("refresh_me_dm", true).commit();
if (settings.notifications && settings.dmsNot && inserted > 0) {
int currentUnread = sharedPrefs.getInt("dm_unread_" + currentAccount, 0);
sharedPrefs.edit().putInt("dm_unread_" + currentAccount, numberNew + currentUnread).commit();
NotificationUtils.refreshNotification(context);
}
if (settings.syncSecondMentions) {
startService(new Intent(context, SecondDMRefreshService.class));
}
sendBroadcast(new Intent("com.klinker.android.twitter.NEW_DIRECT_MESSAGE"));
} catch (TwitterException e) {
// Error in updating status
Log.d("Twitter Update Error", e.getMessage());
}
}
use of twitter4j.TwitterException in project Talon-for-Twitter by klinker24.
the class SecondMentionsRefreshService method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
Context context = getApplicationContext();
AppSettings settings = AppSettings.getInstance(context);
// if they have mobile data on and don't want to sync over mobile data
if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
return;
}
boolean update = false;
int numberNew = 0;
try {
Twitter twitter = Utils.getSecondTwitter(context);
int currentAccount = sharedPrefs.getInt("current_account", 1);
if (currentAccount == 1) {
currentAccount = 2;
} else {
currentAccount = 1;
}
MentionsDataSource dataSource = MentionsDataSource.getInstance(context);
long lastId = dataSource.getLastIds(currentAccount)[0];
Paging paging;
paging = new Paging(1, 200);
if (lastId > 0) {
paging.sinceId(lastId);
}
List<Status> statuses = twitter.getMentionsTimeline(paging);
numberNew = MentionsDataSource.getInstance(context).insertTweets(statuses, currentAccount);
if (numberNew > 0) {
sharedPrefs.edit().putBoolean("refresh_me_mentions", true).commit();
if (settings.notifications && settings.mentionsNot) {
NotificationUtils.notifySecondMentions(context, currentAccount);
}
sendBroadcast(new Intent("com.klinker.android.twitter.REFRESH_SECOND_MENTIONS"));
}
} catch (TwitterException e) {
// Error in updating status
Log.d("Twitter Update Error", e.getMessage());
}
}
use of twitter4j.TwitterException 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.TwitterException 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.TwitterException in project Talon-for-Twitter by klinker24.
the class FavoriterUtils method getFavoriters.
public List<User> getFavoriters(Context context, long tweetId) {
List<User> users = new ArrayList<User>();
Twitter twitter = Utils.getTwitter(context);
try {
Status stat = twitter.showStatus(tweetId);
if (stat.isRetweet()) {
tweetId = stat.getRetweetedStatus().getId();
}
long[] ids = getFavoritersIds(tweetId);
users = twitter.lookupUsers(ids);
} catch (TwitterException e) {
e.printStackTrace();
}
return users;
}
Aggregations