|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectwinterwell.jtwitter.Twitter
public class Twitter
Java wrapper for the Twitter API version 1.3.3
Example usage:
// Make a Twitter object
Twitter twitter = new Twitter("my-name","my-password");
// Print Winterstein's status
System.out.println(twitter.getStatus("winterstein"));
// Set my status
twitter.updateStatus("Messing about in Java");
See http://www.winterwell.com/software/jtwitter.php for more
information about this wrapper. See
http://apiwiki.twitter.com/Twitter-API-Documentation for more
information about the Twitter API.
Notes:
http://www.winterwell.com/software/changelist.txt
| Nested Class Summary | |
|---|---|
static interface |
Twitter.ICallback
Use to register per-page callbacks for long-running searches. |
static interface |
Twitter.IHttpClient
Interface for an http client - e.g. |
static interface |
Twitter.ITweet
This gives common access to features that are common to both Twitter.Messages and Twitter.Statuses. |
static class |
Twitter.Message
A Twitter direct message. |
static class |
Twitter.Status
A Twitter status post. |
static class |
Twitter.User
A Twitter user. |
| Field Summary | |
|---|---|
static java.lang.String |
version
|
| Constructor Summary | |
|---|---|
Twitter()
Create a Twitter client without specifying a user. |
|
Twitter(java.lang.String screenName,
java.lang.String password)
Java wrapper for the Twitter API. |
|
Twitter(java.lang.String name,
Twitter.IHttpClient client)
Java wrapper for the Twitter API. |
|
| Method Summary | |
|---|---|
Twitter.User |
befriend(java.lang.String username)
Deprecated. Use follow(String) instead, which is equivalent. |
Twitter.User |
breakFriendship(java.lang.String username)
Deprecated. Please use stopFollowing(String) instead. |
void |
destroyStatus(long id)
Destroys the status specified by the required ID parameter. |
void |
destroyStatus(Twitter.Status status)
Destroys the given status. |
Twitter.User |
follow(java.lang.String username)
Start following a user. |
void |
follow(Twitter.User user)
Convenience for follow(String) |
static java.util.Date |
getDate(int year,
java.lang.String month,
int day)
Convenience method for making Dates. |
java.util.List<Twitter.Message> |
getDirectMessages()
Returns a list of the direct messages sent to the authenticating user. |
java.util.List<Twitter.Message> |
getDirectMessagesSent()
Returns a list of the direct messages sent *by* the authenticating user. |
java.util.List<Twitter.Status> |
getFavorites()
The most recent 20 favourite tweets. |
java.util.List<Twitter.Status> |
getFavorites(java.lang.String screenName)
The most recent 20 favourite tweets for the given user. |
java.util.List<Twitter.User> |
getFeatured()
Returns a list of the users currently featured on the site with their current statuses inline. |
java.util.List<java.lang.Long> |
getFollowerIDs()
Returns the IDs of the authenticating user's followers. |
java.util.List<java.lang.Long> |
getFollowerIDs(java.lang.String screenName)
Returns the IDs of the specified user's followers. |
java.util.List<Twitter.User> |
getFollowers()
Returns the authenticating user's (latest) followers, each with current status inline. |
java.util.List<Twitter.User> |
getFollowers(java.lang.String username)
Returns the (latest 100) given user's followers, each with current status inline. |
java.util.List<java.lang.Long> |
getFriendIDs()
Returns the IDs of the authenticating user's friends. |
java.util.List<java.lang.Long> |
getFriendIDs(java.lang.String screenName)
Returns the IDs of the specified user's friends. |
java.util.List<Twitter.User> |
getFriends()
Returns the authenticating user's (latest 100) friends, each with current status inline. |
java.util.List<Twitter.User> |
getFriends(java.lang.String username)
Returns the (latest 100) given user's friends, each with current status inline. |
java.util.List<Twitter.Status> |
getFriendsTimeline()
Returns the 20 most recent statuses posted in the last 24 hours from the authenticating user and that user's friends. |
java.util.List<Twitter.Status> |
getPublicTimeline()
Returns the 20 most recent statuses from non-protected users who have set a custom user icon. |
int |
getRateLimitStatus()
|
java.util.List<Twitter.Status> |
getReplies()
Returns the 20 most recent replies/mentions (status updates with |
java.util.List<Twitter.Status> |
getRetweets(Twitter.Status tweet)
|
java.util.List<Twitter.Status> |
getRetweetsOfMe()
TODO @return retweets of your tweets |
java.lang.String |
getScreenName()
|
Twitter.Status |
getStatus()
|
Twitter.Status |
getStatus(long id)
Returns a single status, specified by the id parameter below. |
Twitter.Status |
getStatus(java.lang.String username)
|
java.util.List<java.lang.String> |
getTrends()
|
java.util.Date |
getUntilDate()
TODO document this please - DBW |
Twitter.User |
getUser(long userId)
Synonym for show(long). |
Twitter.User |
getUser(java.lang.String screenName)
Synonym for show(String). |
static Twitter.User |
getUser(java.lang.String screenName,
java.util.List<Twitter.User> users)
Convenience method: Finds a user with the given screen-name from the list. |
java.util.List<Twitter.Status> |
getUserTimeline()
Returns the 20 most recent statuses posted in the last 24 hours from the authenticating user. |
java.util.List<Twitter.Status> |
getUserTimeline(java.lang.String screenName)
Returns the most recent statuses posted in the last 24 hours from the given user. |
boolean |
isFollower(java.lang.String userB)
Is the authenticating user followed by userB? |
boolean |
isFollower(java.lang.String followerScreenName,
java.lang.String followedScreenName)
|
boolean |
isFollowing(java.lang.String userB)
Does the authenticating user follow userB? |
boolean |
isFollowing(Twitter.User user)
Convenience for isFollowing(String) |
boolean |
isValidLogin()
Are the login details used for authentication valid? |
protected static java.lang.String |
jsonGet(java.lang.String key,
org.json.JSONObject jsonObj)
Helper method to deal with JSON-in-Java weirdness |
Twitter.User |
leaveNotifications(java.lang.String screenName)
Switches off notifications for updates from the specified user who must already be a friend. |
static void |
main(java.lang.String[] args)
|
Twitter.User |
notify(java.lang.String username)
Enables notifications for updates from the specified user who must already be a friend. |
Twitter.Status |
retweet(Twitter.Status tweet)
Retweet a tweet without any edits. |
java.util.List<Twitter.Status> |
search(java.lang.String searchTerm)
Wrapper for search(String, ICallback, int) with no callback
and fetching 100 results. |
java.util.List<Twitter.Status> |
search(java.lang.String searchTerm,
Twitter.ICallback callback,
int rpp)
Perform a search of Twitter. |
Twitter.Message |
sendMessage(java.lang.String recipient,
java.lang.String text)
Sends a new direct message to the specified user from the authenticating user. |
void |
setAPIRootUrl(java.lang.String url)
Set this to access sites other than Twitter that support the Twitter API. |
void |
setCount(java.lang.Integer count)
*Some* methods - the timeline ones for example - allow a count of number-of-tweets to return. |
void |
setFavorite(Twitter.Status status,
boolean isFavorite)
|
void |
setLanguage(java.lang.String language)
Set a language filter for search results. |
void |
setMaxResults(int maxResults)
|
void |
setPageNumber(java.lang.Integer pageNumber)
|
void |
setSinceDate(java.util.Date sinceDate)
Date based filter on statuses and messages. |
void |
setSinceId(java.lang.Long statusId)
Narrows the returned results to just those statuses created after the specified status id. |
void |
setSource(java.lang.String sourceApp)
Set the source application. |
Twitter.Status |
setStatus(java.lang.String statusText)
Sets the authenticating user's status. |
void |
setUntilDate(java.util.Date untilDate)
|
Twitter.User |
show(long userId)
Returns information of a given user, specified by user-id. |
Twitter.User |
show(java.lang.String screenName)
Returns information of a given user, specified by screen name. |
java.util.List<java.lang.String> |
splitMessage(java.lang.String longStatus)
Split a long message up into shorter chunks suitable for use with setStatus(String) or sendMessage(String, String). |
Twitter.User |
stopFollowing(java.lang.String username)
Destroy: Discontinues friendship with the user specified in the ID parameter as the authenticating user. |
void |
stopFollowing(Twitter.User user)
Convenience for stopFollowing(String) |
Twitter.Status |
updateStatus(java.lang.String statusText)
Updates the authenticating user's status. |
Twitter.Status |
updateStatus(java.lang.String statusText,
long inReplyToStatusId)
Updates the authenticating user's status and marks it as a reply to the tweet with the given ID. |
boolean |
userExists(java.lang.String screenName)
Does a user with the specified name or id exist? |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String version
| Constructor Detail |
|---|
public Twitter()
public Twitter(java.lang.String name,
Twitter.IHttpClient client)
name - the authenticating user's name, if known. Can be null.client -
public Twitter(java.lang.String screenName,
java.lang.String password)
screenName - The name of the Twitter user. Only used by some methods. Can
be null if you avoid methods requiring authentication.password - The password of the Twitter user. Can be null if you avoid
methods requiring authentication.| Method Detail |
|---|
public void setAPIRootUrl(java.lang.String url)
url - Format: "http://domain-name", e.g. "http://twitter.com" by default.
public static java.util.Date getDate(int year,
java.lang.String month,
int day)
year - month - day -
public static Twitter.User getUser(java.lang.String screenName,
java.util.List<Twitter.User> users)
screenName - aka login nameusers -
protected static java.lang.String jsonGet(java.lang.String key,
org.json.JSONObject jsonObj)
public static void main(java.lang.String[] args)
args - Can be used as a command-line tweet tool. To do so,
enter 3 arguments: name, password, tweet
If empty, prints version info.public void setCount(java.lang.Integer count)
count - null for default behaviour. 200 is the current maximum.
Twitter may reject or ignore high counts.
@Deprecated
public Twitter.User befriend(java.lang.String username)
throws TwitterException
follow(String) instead, which is equivalent.
follow(String). C.f.
http://apiwiki.twitter.com/Migrating-to-followers-terminology
username - Required. The screen name of the user to befriend.
TwitterException@Deprecated public Twitter.User breakFriendship(java.lang.String username)
stopFollowing(String) instead.
stopFollowing(String).
public void destroyStatus(long id)
throws TwitterException
TwitterException
public void destroyStatus(Twitter.Status status)
throws TwitterException
#destroyStatus(int). The
authenticating user must be the author of the status post.
TwitterException
public Twitter.User follow(java.lang.String username)
throws TwitterException
username - Required. The ID or screen name of the user to befriend.
TwitterException - if the user does not exist or has been suspended.public void follow(Twitter.User user)
follow(String)
user - public java.util.List<Twitter.Message> getDirectMessages()
Note: the Twitter API makes this available in rss if that's of interest.
public java.util.List<Twitter.Message> getDirectMessagesSent()
public java.util.List<Twitter.Status> getFavorites()
public void setFavorite(Twitter.Status status,
boolean isFavorite)
public java.util.List<Twitter.Status> getFavorites(java.lang.String screenName)
screenName - login-name.
public java.util.List<Twitter.User> getFeatured()
throws TwitterException
Note: This is no longer part of the Twitter API. Support is provided via other methods.
TwitterException
public java.util.List<java.lang.Long> getFollowerIDs()
throws TwitterException
TwitterException
public java.util.List<java.lang.Long> getFollowerIDs(java.lang.String screenName)
throws TwitterException
The - screen name of the user whose followers are to be fetched.
TwitterException
public java.util.List<Twitter.User> getFollowers()
throws TwitterException
TwitterException
public java.util.List<Twitter.User> getFollowers(java.lang.String username)
throws TwitterException
username - The screen name of the user for whom to request a list
of friends.
TwitterException
public java.util.List<java.lang.Long> getFriendIDs()
throws TwitterException
TwitterException
public java.util.List<java.lang.Long> getFriendIDs(java.lang.String screenName)
throws TwitterException
The - screen name of the user whose friends are to be fetched.
TwitterException
public java.util.List<Twitter.User> getFriends()
throws TwitterException
Note that there seems to be a small delay from Twitter in updates to this list.
TwitterExceptiongetFriendIDs(),
isFollowing(String)
public java.util.List<Twitter.User> getFriends(java.lang.String username)
throws TwitterException
username - The screen name of the user for whom to request a list
of friends.
TwitterException
public java.util.List<Twitter.Status> getFriendsTimeline()
throws TwitterException
TwitterExceptionpublic java.lang.String getScreenName()
public java.util.List<Twitter.Status> getPublicTimeline()
throws TwitterException
Note: Twitter cache-and-refresh this every 60 seconds, so there is little point calling it more frequently than that.
TwitterExceptionpublic int getRateLimitStatus()
public java.util.List<Twitter.Status> getReplies()
throws TwitterException
TwitterExceptionpublic java.util.List<Twitter.Status> getRetweetsOfMe()
public java.util.List<Twitter.Status> getRetweets(Twitter.Status tweet)
public Twitter.Status getStatus()
throws TwitterException
TwitterException
public Twitter.Status getStatus(long id)
throws TwitterException
id - The numerical ID of the status you're trying to retrieve.
TwitterException
public Twitter.Status getStatus(java.lang.String username)
throws TwitterException
TwitterException
public java.util.List<Twitter.Status> getUserTimeline()
throws TwitterException
TwitterException
public java.util.List<Twitter.Status> getUserTimeline(java.lang.String screenName)
throws TwitterException
This method will authenticate if it can (i.e. if the Twitter object has a username and password). Authentication is needed to see the posts of a private user.
screenName - Can be null. Specifies the screen name of the user for
whom to return the user_timeline.since - Can be null. Narrows the returned results to just those
statuses created after the specified date.
TwitterExceptionpublic boolean isFollower(java.lang.String userB)
userB - The screen name of a Twitter user.
public boolean isFollower(java.lang.String followerScreenName,
java.lang.String followedScreenName)
TwitterException.E403 - if one of the users has protected their
updates and you don't have access. This can be counter-intuitive
(and annoying) at times!public boolean isFollowing(java.lang.String userB)
userB - The screen name of a Twitter user.
public boolean isFollowing(Twitter.User user)
isFollowing(String)
user - public boolean isValidLogin()
public Twitter.User leaveNotifications(java.lang.String screenName)
screenName - Stop getting notifications from this user, who must already be
one of your friends.
public Twitter.User notify(java.lang.String username)
username - Get notifications from this user, who must already be one of
your friends.
public java.util.List<Twitter.Status> search(java.lang.String searchTerm,
Twitter.ICallback callback,
int rpp)
Warning: the User objects returned by a search (as part of the Status objects)
are dummy-users. The only information that is set is the user's screen-name
and a profile image url. This reflects the current behaviour of the Twitter API.
If you need more info, call show(String) with the screen name.
This supports maxResults and pagination.
A language filter can be set via setLanguage(String)
TODO parameters:
geocode: Optional. Returns tweets by users located within a given
radius of the given latitude/longitude, where the user's location
is taken from their Twitter profile. The parameter value is specified
by "latitude,longitude,radius", where radius units must be specified as
either "mi" (miles) or "km" (kilometers). Note that you cannot use the
near operator via the API to geocode arbitrary locations; however you can use
this geocode parameter to search near geocodes directly.
searchTerm - callback - an object whose process() method will be called on each
new page of results.the - number of results to fetch per page
public Twitter.Status retweet(Twitter.Status tweet)
tweet - This must not be one of your own or Twitter will
ignore it.
public java.util.List<Twitter.Status> search(java.lang.String searchTerm)
search(String, ICallback, int) with no callback
and fetching 100 results.
Perform a search of Twitter.
Warning: the User objects returned by a search (as part of the Status objects)
are dummy-users. The only information that is set is the user's screen-name
and a profile image url. This reflects the current behaviour of the Twitter API.
If you need more info, call show(String) with the screen name.
This supports maxResults and pagination.
A language filter can be set via setLanguage(String)
TODO parameters:
geocode: Optional. Returns tweets by users located within a given
radius of the given latitude/longitude, where the user's location
is taken from their Twitter profile. The parameter value is specified
by "latitude,longitude,radius", where radius units must be specified as
either "mi" (miles) or "km" (kilometers). Note that you cannot use the
near operator via the API to geocode arbitrary locations; however you can use
this geocode parameter to search near geocodes directly.
searchTerm -
public Twitter.Message sendMessage(java.lang.String recipient,
java.lang.String text)
throws TwitterException
recipient - Required. The screen name of the recipient user.text - Required. The text of your direct message. Keep it under 140
characters! This should *not* include the "d username" portion
TwitterException.E403 - if the recipient is not following you.
(you can \@mention anyone but you can only dm people who follow you).
TwitterExceptionpublic void setMaxResults(int maxResults)
maxResults - if greater than zero, requests will attempt to fetch as many
pages as are needed! -1 by default, in which case most methods
return the first 20 statuses/messages.
If setting a high figure, you should usually also set a sinceId or sinceDate to limit your Twitter usage. Otherwise you can easily exceed your rate limit.
public void setPageNumber(java.lang.Integer pageNumber)
pageNumber - null (the default) returns the first page. Pages are indexed
from 1. This is used once only! Then it is reset to nullpublic void setSinceDate(java.util.Date sinceDate)
If using this, you probably also want to increase
setMaxResults(int) - otherwise you get at most 20, and possibly
less (since the filtering is done client side).
sinceDate - public void setUntilDate(java.util.Date untilDate)
untilDate - the untilDate to setpublic java.util.Date getUntilDate()
public void setSinceId(java.lang.Long statusId)
If using this, you probably also want to increase
setMaxResults(int) (otherwise you just get the most recent 20).
statusId - public void setSource(java.lang.String sourceApp)
sourceApp - jtwitterlib by default. Set to null for no source.
public Twitter.Status setStatus(java.lang.String statusText)
throws TwitterException
Identical to updateStatus(String), but with a Java-style name
(updateStatus is the Twitter API name for this method).
statusText - The text of your status update. Must not be more than 160
characters and should not be more than 140 characters to
ensure optimal display.
TwitterException
public Twitter.User show(java.lang.String screenName)
throws TwitterException
screenName - The screen name of a user.
exception - if the user does not exist - or has been terminated
(as happens to spam bots).
TwitterExceptionshow(long)public Twitter.User show(long userId)
userId - The user-id of a user.
exception - if the user does not exist - or has been terminated
(as happens to spam bots).public Twitter.User getUser(java.lang.String screenName)
show(String).
show is the Twitter API name, getUser feels more Java-like.
screenName - The screen name of a user.
public Twitter.User getUser(long userId)
show(long).
show is the Twitter API name, getUser feels more Java-like.
userId - The user-id of a user.
getUser(String)public java.util.List<java.lang.String> splitMessage(java.lang.String longStatus)
setStatus(String) or sendMessage(String, String).
longStatus -
public Twitter.User stopFollowing(java.lang.String username)
username - The screen name of the user with whom to discontinue
friendship.
public void stopFollowing(Twitter.User user)
stopFollowing(String)
user - public Twitter.Status updateStatus(java.lang.String statusText)
statusText - The text of your status update. Must not be more than 160
characters and should not be more than 140 characters to
ensure optimal display.
public Twitter.Status updateStatus(java.lang.String statusText,
long inReplyToStatusId)
throws TwitterException
statusText - The text of your status update. Must not be more than 160
characters and should not be more than 140 characters to
ensure optimal display.inReplyToStatusId - The ID of the tweet that this tweet is in response to.
The statusText must contain the username (with an "@"
prefix) of the owner of the tweet being replied to for
for Twitter to agree to mark the tweet as a reply.
0 or less to leave this unset.
TwitterExceptionpublic boolean userExists(java.lang.String screenName)
screenName - The screen name or user id of the suspected user.
public void setLanguage(java.lang.String language)
language - ISO code for language. Can be null for all languages.public java.util.List<java.lang.String> getTrends()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||