use of twitter4j.Twitter in project twicalico by moko256.
the class GlobalApplication method getTwitterInstance.
@NonNull
public Twitter getTwitterInstance(@NonNull AccessToken accessToken) {
Twitter t;
Configuration conf;
if (accessToken.getType() == Type.TWITTER) {
conf = new ConfigurationBuilder().setTweetModeExtended(true).setOAuthConsumerKey(BuildConfig.CONSUMER_KEY).setOAuthConsumerSecret(BuildConfig.CONSUMER_SECRET).setOAuthAccessToken(accessToken.getToken()).setOAuthAccessTokenSecret(accessToken.getTokenSecret()).build();
t = twitterCache.get(conf);
if (t == null) {
t = new TwitterFactory(conf).getInstance();
twitterCache.put(conf, t);
}
} else {
conf = new ConfigurationBuilder().setOAuthAccessToken(accessToken.getToken()).setRestBaseURL(accessToken.getUrl()).build();
t = twitterCache.get(conf);
if (t == null) {
t = new MastodonTwitterImpl(conf, accessToken.getUserId(), getOkHttpClient(conf.getHttpClientConfiguration()).newBuilder());
twitterCache.put(conf, t);
}
}
return t;
}
use of twitter4j.Twitter in project opennms by OpenNMS.
the class MicroblogNotificationStrategy method send.
/**
* {@inheritDoc}
*/
@Override
public int send(List<Argument> arguments) {
Twitter svc = buildUblogService(arguments);
String messageBody = buildMessageBody(arguments);
Status response;
final String baseURL = svc.getConfiguration().getClientURL();
LOG.debug("Dispatching microblog notification at base URL '{}' with message '{}'", baseURL, messageBody);
try {
response = svc.updateStatus(messageBody);
} catch (TwitterException e) {
LOG.error("Microblog notification failed at service URL '{}'", baseURL, e);
return 1;
}
LOG.info("Microblog notification succeeded: update posted with ID {}", response.getId());
return 0;
}
use of twitter4j.Twitter in project opennms by OpenNMS.
the class MicroblogReplyNotificationStrategy method send.
/**
* {@inheritDoc}
*/
@Override
public int send(final List<Argument> arguments) {
final Twitter svc = buildUblogService(arguments);
String destUser = findDestName(arguments);
Status response;
if (destUser == null || "".equals(destUser)) {
LOG.error("Cannot send a microblog reply notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead.");
return 1;
}
// In case the user tried to be helpful, avoid a double @@
if (destUser.startsWith("@"))
destUser = destUser.substring(1);
final String fullMessage = String.format("@%s %s", destUser, buildMessageBody(arguments));
LOG.debug("Dispatching microblog reply notification at base URL '{}' with message '{}'", svc.getConfiguration().getClientURL(), fullMessage);
try {
response = svc.updateStatus(fullMessage);
} catch (final TwitterException e) {
LOG.error("Microblog notification failed at service URL '{}'", svc.getConfiguration().getClientURL(), e);
return 1;
}
LOG.info("Microblog reply notification succeeded: reply update posted with ID {}", response.getId());
return 0;
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class FavoritesActivity method getFavorites.
public void getFavorites() {
if (!hasMore) {
return;
}
canRefresh = false;
final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
final ResponseList<twitter4j.Status> favs = twitter.getFavorites(paging);
if (favs.size() < 17) {
hasMore = false;
}
paging.setPage(paging.getPage() + 1);
for (twitter4j.Status s : favs) {
statuses.add(s);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (adapter == null) {
if (statuses.size() > 0) {
adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.FAVORITE);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
} else {
LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
nothing.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
hasMore = false;
}
} else {
adapter.notifyDataSetChanged();
}
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;
}
});
} catch (OutOfMemoryError 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 Talon-for-Twitter by klinker24.
the class RetweetActivity method getRetweets.
public void getRetweets() {
if (!hasMore) {
return;
}
canRefresh = false;
final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
final ResponseList<twitter4j.Status> favs = twitter.getRetweetsOfMe(paging);
if (favs.size() < 17) {
hasMore = false;
}
paging.setPage(paging.getPage() + 1);
for (twitter4j.Status s : favs) {
statuses.add(s);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (adapter == null) {
if (statuses.size() > 0) {
adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.RETWEET);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
} else {
LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
try {
nothing.setVisibility(View.VISIBLE);
} catch (Exception e) {
}
listView.setVisibility(View.GONE);
}
} else {
adapter.notifyDataSetChanged();
}
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;
}
});
} catch (OutOfMemoryError e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
canRefresh = false;
}
});
}
}
}).start();
}
Aggregations