public class Twitter
extends java.lang.Object
implements java.io.Serializable
Example usage:
First, you should get the user to authorise access via OAuth. There are a
couple of ways of doing this -- we show one below -- see
OAuthSignpostClient
for more details.
Now we can access Twitter:
// First, OAuth to login: Make an oauth client
OAuthSignpostClient oauthClient = new OAuthSignpostClient(JTWITTER_OAUTH_KEY, JTWITTER_OAUTH_SECRET, "oob");
// open the authorisation page in the user's browser
oauthClient.authorizeDesktop(); // Note: this only works on desktop PCs
// or direct the user to the webpage given jby oauthClient.authorizeUrl()
// get the pin from the user since we're using "oob" instead of a callback servlet
String v = oauthClient.askUser("Please enter the verification PIN from Twitter");
oauthClient.setAuthorizationCode(v);
// You can store the authorisation token details for future use
Object accessToken = client.getAccessToken();
// Make a Twitter object
Twitter twitter = new Twitter("my-name", oauthClient);
// Print Winterstein's status
System.out.println(twitter.getStatus("winterstein"));
// Set my status
twitter.updateStatus("Messing about in Java");
If you can handle callbacks, then the OAuth login can be streamlined. You need a webserver and a servlet (eg. use Jetty or Tomcat) to handle callbacks. Replace "oob" with your callback url. Direct the user to client.authorizeUrl(). Twitter will then call your callback with the request token and verifier (authorisation code).
See http://www.winterwell.com/software/jtwitter.php
for more
information about this wrapper. See http://dev.twitter.com/doc
for
more information about the Twitter API.
Notes:
users()
, geo()
, and account()
.
For list support see TwitterList
- though getLists()
is here.
://www.winterwell.com/software/changelist.txt
Modifier and Type | Class and Description |
---|---|
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
|
static class |
Twitter.KEntityType |
static class |
Twitter.KRequestType
Deprecated.
Replaced in 1.1 with a more flexible family of resources.
Kept here for backwards compatibility only.
Will be removed: June 2013!
|
static class |
Twitter.TweetEntity
A special slice of text within a tweet.
|
Modifier and Type | Field and Description |
---|---|
static boolean |
CASE_SENSITIVE_SCREENNAMES
This rather dangerous global toggle switches off lower-casing on Twitter
screen-names.
|
static boolean |
CHECK_TWEET_LENGTH
This global toggle switches on/off length-checking for tweets.
|
static int |
LINK_LENGTH
The length of a url after t.co shortening.
|
static int |
MAX_CHARS
The maximum number of characters that a tweet can contain.
|
static int |
MAX_DM_LENGTH |
static int |
MEDIA_LENGTH
The characters used up by an attached image.
|
static long |
PHOTO_SIZE_LIMIT
3mb
https://dev.twitter.com/rest/media/uploading-media Note: "It is possible to upload a 5 MB image, but the Tweet creation requires images to be <= 3 MB" |
static java.lang.String |
SEARCH_MIXED |
static java.lang.String |
SEARCH_POPULAR |
static java.lang.String |
SEARCH_RECENT
return the most recent results in the response
|
static java.lang.String |
version
JTwitter version
|
static long |
VIDEO_SIZE_LIMIT
15mb
|
static boolean |
WORRIED_ABOUT_TWITTER
Deprecated.
Not used at present
Set to true to perform extra error-handling & correction.
|
Constructor and Description |
---|
Twitter()
Deprecated.
ALL twitter.com endpoints now require authentication.
This method is kept for use with other services (e.g. identi.ca).
Create a Twitter client without specifying a user. |
Twitter(java.lang.String screenName,
java.lang.String password)
Deprecated.
|
Twitter(java.lang.String name,
Twitter.IHttpClient client)
Java wrapper for the Twitter API.
|
Twitter(Twitter jtwit)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
Twitter_Account |
account()
API methods relating to your account.
|
Twitter_Analytics |
analytics()
API methods for Twitter stats.
|
User |
befriend(java.lang.String username)
Deprecated.
Use
follow(String) instead, which is equivalent. |
User |
breakFriendship(java.lang.String username)
Deprecated.
Please use
stopFollowing(String) instead. |
java.util.List<User> |
bulkShow(java.util.List<java.lang.String> screenNames)
Deprecated.
Use
Twitter_Users#show(List) instead |
java.util.List<User> |
bulkShowById(java.util.List<? extends java.lang.Number> userIds)
Deprecated.
Use
#showById(List) instead |
java.lang.Integer |
countAccountActivitySubscriptions(java.lang.String envName)
Return the total number of account activity subscriptions on the specified environment.
|
static int |
countCharacters(java.lang.String statusText)
Compute the effective size of a message, given that Twitter treats things that
smell like a URL as 23 characters.
|
void |
destroy(Twitter.ITweet tweet)
Deletes the given Status or Message.
|
void |
destroyMessage(java.lang.Number id)
Deletes the direct message specified by the ID.
|
void |
destroyStatus(java.lang.Number id)
Deletes the status specified by the required ID parameter.
|
void |
destroyStatus(Status status)
Deprecated.
in favour of
destroy(ITweet) . This method will be
removed by the end of 2010. |
void |
enableAppAuth(java.lang.String token)
Save a previously-obtained bearer token so this instance can use app-level methods
|
void |
enableAppAuth(java.lang.String key,
java.lang.String secret)
Save the application key and secret so this instance can retrieve a bearer token for app-level methods
(e.g.
|
User |
follow(java.lang.String username)
Deprecated.
|
User |
follow(User user)
Deprecated.
|
Twitter_Geo |
geo()
Geo-location API methods.
|
static java.util.Map<java.lang.String,java.lang.Double> |
getAPIStatus()
How is the Twitter API today?
See
https://dev.twitter.com/status for more information. |
Message |
getDirectMessage(java.lang.Number id)
Returns a single direct message to the authenticating user, specified by ID
|
java.util.List<Message> |
getDirectMessages()
Returns a list of the direct messages to AND from the authenticating user.
|
java.io.InputStream |
getDMImage(Message msg) |
java.util.List<Status> |
getFavorites()
The most recent 20 favourite tweets.
|
java.util.List<Status> |
getFavorites(java.lang.String screenName)
The most recent 20 favourite tweets for the given user.
|
java.util.List<java.lang.Number> |
getFollowerIDs()
Deprecated.
|
java.util.List<java.lang.Number> |
getFollowerIDs(java.lang.String screenName)
Deprecated.
|
java.util.List<User> |
getFollowers()
Deprecated.
|
java.util.List<User> |
getFollowers(java.lang.String username)
Deprecated.
|
java.util.List<java.lang.Number> |
getFriendIDs()
Deprecated.
|
java.util.List<java.lang.Number> |
getFriendIDs(java.lang.String screenName)
Deprecated.
|
java.util.List<User> |
getFriends()
Deprecated.
|
java.util.List<User> |
getFriends(java.lang.String username)
Deprecated.
|
java.util.List<Status> |
getFriendsTimeline()
Deprecated.
Replaced by
getHomeTimeline() |
java.util.List<Status> |
getHomeTimeline()
Returns the 20 most recent statuses posted in the last 24 hours from the
authenticating user and that user's friends, including retweets.
|
Twitter.IHttpClient |
getHttpClient()
Provides access to the
Twitter.IHttpClient which manages the low-level
authentication, posts and gets. |
java.util.List<TwitterList> |
getLists() |
java.util.List<TwitterList> |
getLists(java.lang.String screenName) |
java.util.List<TwitterList> |
getListsAll(User user)
Returns all lists the authenticating or specified user subscribes to,
including their own.
|
java.util.List<TwitterList> |
getListsContaining(java.lang.String screenName,
boolean filterToOwned) |
java.util.List<TwitterList> |
getListsContainingMe()
Convenience for
getListsContaining(String, boolean) . |
java.lang.String |
getLongStatus(Status truncatedStatus)
Deprecated.
Use
TwitLonger |
int |
getMaxResults()
Provides support for fetching many pages.
|
java.util.List<Status> |
getMentions()
Returns the 20 most recent replies/mentions (status updates with
\@username) to the authenticating user.
|
RateLimit |
getRateLimit(Twitter.KRequestType reqType)
Deprecated.
Use getHttpClient().getRateLimits()
What is the current rate limit status? Do we need to throttle back our
usage? This is the cached info from the last call of that type.
Note: The RateLimit object is created using cached info from a previous Twitter call. So this method is quick (it doesn't require a fresh call to Twitter), but the RateLimit object isn't available until after you make a call of the right type to Twitter. Status: Heading towards stable, but still a bit experimental. |
int |
getRateLimitStatus()
Deprecated.
Not in v1.1
How many normal rate limit calls do you have left? This calls Twitter,
which makes it slower than
getRateLimit(KRequestType) but it's
up-to-date and safe against threads and other-programs using the same
allowance.
This may update getRateLimit(KRequestType) for NORMAL requests, but sadly it doesn't fetch rate-limit info on other request types. |
java.util.List<Status> |
getReplies()
Deprecated.
Use #getMentions() for preference. This method will be removed June 2013.
|
java.util.List<User> |
getRetweeters(Status tweet)
Show users who (new-style) retweeted the given tweet.
|
java.util.List<Status> |
getRetweets(Status tweet) |
java.util.List<Status> |
getRetweetsByMe()
Deprecated.
Removed in api v1.1. Simulated with other methods. Will be removed June 2013
|
java.util.List<Status> |
getRetweetsOfMe() |
java.lang.String |
getScreenName() |
java.lang.String |
getScreenNameIfKnown()
Equivalent to
getScreenName() except this won't ever do
an API call. |
java.lang.String |
getSearchLocation() |
User |
getSelf() |
java.math.BigInteger |
getSinceId() |
Status |
getStatus() |
Status |
getStatus(java.lang.Number id)
Returns a single status, specified by the id parameter below.
|
Status |
getStatus(java.lang.String username) |
java.util.List<java.lang.String> |
getTrends() |
java.util.List<java.lang.String> |
getTrends(java.lang.Number woeid) |
java.util.Date |
getUntilDate() |
java.math.BigInteger |
getUntilId() |
User |
getUser(long userId)
Deprecated.
|
User |
getUser(java.lang.String screenName)
Deprecated.
|
static User |
getUser(java.lang.String screenName,
java.util.List<User> users)
Convenience method: Finds a user with the given screen-name from the
list.
|
java.util.List<Status> |
getUserTimeline()
Returns the most recent statuses from the authenticating user.
|
java.util.List<Status> |
getUserTimeline(java.lang.Long userId)
Equivalent to
getUserTimeline(String) , but takes a numeric
user-id instead of a screen-name. |
java.util.List<Status> |
getUserTimeline(java.lang.String screenName)
Returns the most recent statuses from the given user.
|
java.util.List<Status> |
getUserTimelineWithRetweets(java.lang.String screenName)
Deprecated.
Use
setIncludeRTs(boolean) instead to control
retweet behaviour.
Returns the most recent statuses posted by the given user.
Unlike getUserTimeline(String) , this includes
new-style retweets.
This will return 20 by default, though
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. |
Webhooks.WebhookList |
getWebhooks()
Return a list of registered Webhooks for the application
|
boolean |
isFollower(java.lang.String userB)
Deprecated.
|
boolean |
isFollower(java.lang.String followerScreenName,
java.lang.String followedScreenName)
Deprecated.
|
boolean |
isFollowing(java.lang.String userB)
Deprecated.
|
boolean |
isFollowing(User user)
Deprecated.
|
boolean |
isRateLimited(java.lang.String apiResourceName,
boolean defaultIfUnset)
Convenience for using getHttpClient().getRateLimits()
|
boolean |
isRateLimited(Twitter.KRequestType reqType,
int minCalls)
Deprecated.
Are we rate-limited, based on cached info from previous requests?
|
boolean |
isTwitlongerSetup()
Deprecated.
Use
TwitLonger
Keeping for backwards compatibility until Q2 2013 |
boolean |
isValidLogin()
Are the login details used for authentication valid?
|
java.util.List<Webhooks.Subscription> |
listAccountActivitySubscriptions(java.lang.String envName)
Return a list of account activity subscriptions on the specified environment
|
static void |
main(java.lang.String[] args) |
java.math.BigInteger |
registerWebhook(java.lang.String webhookUrl,
java.lang.String envName)
Register a new Webhooks URL, to which all updates for the specified environment will be sent.
|
void |
reportSpam(java.lang.String screenName)
Report a user for being a spammer.
|
Status |
retweet(Status tweet)
Retweet (new-style) a tweet without any edits.
|
Status |
retweetWithComment(Status tweet,
java.lang.String comment)
Retweet, adding a comment.
|
java.util.List<Status> |
search(java.lang.String searchTerm)
Perform a search of Twitter.
|
java.util.List<Status> |
search(java.lang.String searchTerm,
Twitter.ICallback callback,
int rpp)
Perform a search of Twitter.
|
java.util.List<User> |
searchUsers(java.lang.String searchTerm)
Deprecated.
|
Message |
sendMessage(java.lang.String recipientId,
java.lang.String text)
Sends a new direct message (DM) 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 |
setAutoPopulateReplyMetadata(java.lang.Boolean autoPopulateReplyMetadata)
Compatibility setting: if your app can't generate new-style
"previously tagged-in users are implicitly included in replies"
tweets, turn this off to require users be explicitly tagged in every time.
|
void |
setCount(java.lang.Integer count)
*Some* methods - the timeline ones for example - allow a count of
number-of-tweets to return.
|
void |
setExtendedMode(java.lang.Boolean extendedMode)
Compatibility setting: if your app can't work with new-style
"140 characters + attachment" tweets, turn this off to only
receive truncated results.
|
Status |
setFavorite(Status status,
boolean isFavorite) |
void |
setIncludeRTs(boolean includeRTs)
true by default.
|
void |
setIncludeTweetEntities(boolean tweetEntities)
Note: does NOT work for search() methods (not supported by Twitter).
|
void |
setLanguage(java.lang.String language)
Set a language filter for search results.
|
void |
setMaxResults(int maxResults) |
void |
setMyLocation(double[] latitudeLongitude)
Set the location for your tweets.
Warning: geo-tagging parameters are ignored if geo_enabled for the user is false (this is the default setting for all users unless the user has enabled geolocation in their settings)! |
void |
setMyPlace(java.lang.Long placeId)
If set, this will place-id be sent with status-updates to geo-tag your tweets.
|
void |
setSearchLocation(double latitude,
double longitude,
java.lang.String radius)
Restricts
search(String) to tweets by users located within a
given radius of the given latitude/longitude. |
void |
setSearchLocation(com.winterwell.jgeoplanet.IPlace place) |
void |
setSearchResultType(java.lang.String resultType)
Optional.
|
void |
setSinceDate(java.util.Date sinceDate)
Deprecated.
|
void |
setSinceId(java.lang.Number 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.
|
Status |
setStatus(java.lang.String statusText)
Sets the authenticating user's status.
|
void |
setUntilDate(java.util.Date untilDate)
Deprecated.
|
void |
setUntilId(java.lang.Number untilId)
If set, return results older than this.
|
void |
setupTwitlonger(java.lang.String twitlongerAppName,
java.lang.String twitlongerApiKey)
Deprecated.
User
TwitLonger
Keeping for backwards compatibility until Q2 2013
Set this to allow the use of twitlonger via
#updateLongStatus(String, long) . To get an api-key for your app,
contact twitlonger as described here: http://www.twitlonger.com/api
This method will be removed June 2013 |
User |
show(java.lang.Number userId)
Deprecated.
|
User |
show(java.lang.String screenName)
Deprecated.
|
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) . |
User |
stopFollowing(java.lang.String username)
Deprecated.
|
User |
stopFollowing(User user)
Deprecated.
|
void |
subscribeAccountActivity(java.lang.String envName)
Start sending activity updates for the authorised account to the Webhooks URLs registered to the specified environment.
|
java.lang.String |
toString() |
void |
unregisterWebhook(java.math.BigInteger webhookId,
java.lang.String envName)
Unregister a Webhooks URL - updates for the specified environment will no longer be sent to it.
|
void |
unsubscribeAccountActivity(java.lang.String envName)
Stop sending activity updates for the authorised account to the Webhooks URLs registered to the specified environment.
|
boolean |
updateConfiguration()
Update info on Twitter's configuration -- such as shortened url lengths.
|
Status |
updateLongStatus(java.lang.String message,
java.lang.Number inReplyToStatusId)
Deprecated.
Use
TwitLonger
Keeping for backwards compatibility until Q2 2013
Use twitlonger.com to post a lengthy tweet. See twitlonger.com for more
details on their service.
Note: You need to have called |
Status |
updateStatus(java.lang.String statusText)
Updates the authenticating user's status.
|
Status |
updateStatus(java.lang.String statusText,
java.lang.Number inReplyToStatusId)
Compatibility wrapper for
updateStatus(String, Number, List |
Status |
updateStatus(java.lang.String statusText,
java.lang.Number inReplyToStatusId,
java.util.List<java.lang.Number> excludeReplyIds)
Updates the authenticating user's status and marks it as a reply to the
tweet with the given ID.
|
Status |
updateStatusWithMedia(java.lang.String statusText,
java.math.BigInteger inReplyToStatusId,
java.io.File mediaFile)
Compatibility wrapper for {@link updateStatusWithMedia(String, BigInteger, List
|
Status |
updateStatusWithMedia(java.lang.String statusText,
java.math.BigInteger inReplyToStatusId,
java.util.List<java.io.File> mediaFiles)
Compatibility wrapper for
updateStatusWithMedia(String, BigInteger, List |
Status |
updateStatusWithMedia(java.lang.String statusText,
java.math.BigInteger inReplyToStatusId,
java.util.List<java.lang.Number> excludedIds,
java.io.File mediaFile)
Updates the user's status with a single image.
|
Status |
updateStatusWithMedia(java.lang.String statusText,
java.math.BigInteger inReplyToStatusId,
java.util.List<java.lang.Number> excludedIds,
java.util.List<java.io.File> mediaFiles)
Updates the user's status with multiple images.
|
Status |
updateStatusWithUploadedMedia(java.lang.String statusText,
java.math.BigInteger inReplyToStatusId,
java.util.List<java.lang.Number> excludedIds,
java.util.List<java.lang.String> mediaFileIds)
Updates the user's status with one video, or multiple images.
|
Status |
updateStatusWithUploadedMedia(java.lang.String statusText,
java.math.BigInteger inReplyToStatusId,
java.util.List<java.lang.String> mediaFileIds)
Compatibility wrapper for
updateStatusWithUploadedMedia(String, BigInteger, List |
Status |
updateStatusWithVideo(java.lang.String text,
java.io.File video)
Convenience for using
uploadVideo(File)
+ updateStatusWithUploadedMedia(String, BigInteger, List) |
java.lang.String |
uploadVideo(java.io.File video)
See https://dev.twitter.com/rest/media/uploading-media#chunkedupload
|
java.lang.String |
uploadVideo(java.io.File video,
java.lang.String mimeType,
boolean async)
See https://dev.twitter.com/rest/media/uploading-media#chunkedupload
|
Twitter_Users |
users()
User and social-network related API methods.
|
public static boolean CASE_SENSITIVE_SCREENNAMES
Screen-names are case insensitive as far as Twitter is concerned. However you might want to preserve the case people use for display purposes.
false by default.
public static boolean CHECK_TWEET_LENGTH
To avoid wasting time or API rate-limit usage, JTwitter can check that outgoing tweets meet the maximum-length restriction. Set this to false to disable that check (Twitter will still apply their own check!).
true by default.
countCharacters(String)
public static int LINK_LENGTH
Use updateConfiguration()if you want to get the latest settings from Twitter.
public static int MEDIA_LENGTH
Use updateConfiguration()if you want to get the latest settings from Twitter.
public static long PHOTO_SIZE_LIMIT
public static long VIDEO_SIZE_LIMIT
public static final java.lang.String SEARCH_MIXED
public static final java.lang.String SEARCH_POPULAR
public static final java.lang.String SEARCH_RECENT
public static final java.lang.String version
public static final int MAX_CHARS
public static int MAX_DM_LENGTH
public static boolean WORRIED_ABOUT_TWITTER
public Twitter()
Create a Twitter client without specifying a user.
public Twitter(java.lang.String name, Twitter.IHttpClient client)
name
- the authenticating user's name, if known. Can be null.client
- e.g. OAuthSignpostClientOAuthSignpostClient
@Deprecated public Twitter(java.lang.String screenName, java.lang.String password)
screenName
- The name of the user. Only used by some methods.password
- The password of the user.public Twitter(Twitter jtwit)
jtwit
- public static java.util.Map<java.lang.String,java.lang.Double> getAPIStatus() throws java.lang.Exception
https://dev.twitter.com/status
for more information.java.lang.Exception
- This method is not officially supported! As such,
it could break at some future point.public static User getUser(java.lang.String screenName, java.util.List<User> users)
screenName
- aka login nameusers
- 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 setMyPlace(java.lang.Long placeId)
placeId
- Can be null (which is the default)setMyLocation(double[])
public Twitter_Account account()
public Twitter_Analytics analytics()
@Deprecated public 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-terminologyusername
- Required. The screen name of the user to befriend.TwitterException
@Deprecated public User breakFriendship(java.lang.String username)
stopFollowing(String)
instead.stopFollowing(String)
.public java.util.List<User> bulkShow(java.util.List<java.lang.String> screenNames)
Twitter_Users#show(List)
insteadpublic java.util.List<User> bulkShowById(java.util.List<? extends java.lang.Number> userIds)
#showById(List)
insteadpublic void destroy(Twitter.ITweet tweet) throws TwitterException
TwitterException
public void destroyMessage(java.lang.Number id)
destroy(ITweet)
public void destroyStatus(java.lang.Number id) throws TwitterException
TwitterException
destroy(ITweet)
@Deprecated public void destroyStatus(Status status) throws TwitterException
destroy(ITweet)
. This method will be
removed by the end of 2010.#destroyStatus(int)
. The
authenticating user must be the author of the status post.TwitterException
destroy(ITweet)
@Deprecated public User follow(java.lang.String username) throws TwitterException
TwitterException
Twitter_Users.follow(String)
public java.lang.String toString()
toString
in class java.lang.Object
@Deprecated public User follow(User user)
Twitter_Users.follow(User)
public Twitter_Geo geo()
public Message getDirectMessage(java.lang.Number id)
id
- The DM ID.public java.util.List<Message> getDirectMessages()
Note: the Twitter API makes this available in rss if that's of interest.
public java.util.List<Status> getFavorites()
public java.util.List<Status> getFavorites(java.lang.String screenName)
screenName
- login-name.@Deprecated public java.util.List<java.lang.Number> getFollowerIDs() throws TwitterException
TwitterException
Twitter_Users.getFollowerIDs()
@Deprecated public java.util.List<java.lang.Number> getFollowerIDs(java.lang.String screenName) throws TwitterException
TwitterException
Twitter_Users.getFollowerIDs(String)
@Deprecated public java.util.List<User> getFollowers() throws TwitterException
TwitterException
Twitter_Users.getFollowers()
@Deprecated public java.util.List<User> getFollowers(java.lang.String username) throws TwitterException
TwitterException
Twitter_Users.getFollowers(String)
@Deprecated public java.util.List<java.lang.Number> getFriendIDs() throws TwitterException
TwitterException
Twitter_Users.getFriendIDs()
@Deprecated public java.util.List<java.lang.Number> getFriendIDs(java.lang.String screenName) throws TwitterException
TwitterException
Twitter_Users.getFriendIDs(String)
@Deprecated public java.util.List<User> getFriends() throws TwitterException
TwitterException
Twitter_Users.getFriends()
@Deprecated public java.util.List<User> getFriends(java.lang.String username) throws TwitterException
TwitterException
Twitter_Users#getFriendss(String)
@Deprecated public java.util.List<Status> getFriendsTimeline() throws TwitterException
getHomeTimeline()
TwitterException
public java.util.List<Status> getHomeTimeline() throws TwitterException
TwitterException
public Twitter.IHttpClient getHttpClient()
Twitter.IHttpClient
which manages the low-level
authentication, posts and gets.public java.util.List<TwitterList> getLists()
public java.util.List<TwitterList> getListsAll(User user)
user
- can be null for the authenticating user.getLists(String)
public java.util.List<TwitterList> getLists(java.lang.String screenName)
screenName
- public java.util.List<TwitterList> getListsContaining(java.lang.String screenName, boolean filterToOwned)
screenName
- filterToOwned
- If true, only return lists which the user owns.public java.util.List<TwitterList> getListsContainingMe()
getListsContaining(String, boolean)
.public java.lang.String getLongStatus(Status truncatedStatus)
TwitLonger
truncatedStatus
- If this is a twitlonger.com truncated status, then call
twitlonger to fetch the full text.#updateLongStatus(String, long)
public int getMaxResults()
public java.util.List<Status> getMentions()
This is exactly the same as getReplies()
When paging, this method can only go back up to 800 statuses.
Does not include new-style retweets.
public RateLimit getRateLimit(Twitter.KRequestType reqType)
Note: The RateLimit object is created using cached info from a previous Twitter call. So this method is quick (it doesn't require a fresh call to Twitter), but the RateLimit object isn't available until after you make a call of the right type to Twitter.
Status: Heading towards stable, but still a bit experimental.
reqType
- Different methods have separate rate limits.getRateLimitStatus()
public int getRateLimitStatus()
getRateLimit(KRequestType)
but it's
up-to-date and safe against threads and other-programs using the same
allowance.
This may update getRateLimit(KRequestType) for NORMAL requests, but sadly it doesn't fetch rate-limit info on other request types.
getRateLimit(KRequestType)
public java.util.List<Status> getReplies() throws TwitterException
TwitterException
public java.util.List<User> getRetweeters(Status tweet)
tweet
- You can use a "fake" Status created via
Status#Status(User, String, long, Date)
if you know
the id number.public java.util.List<Status> getRetweets(Status tweet)
public java.util.List<Status> getRetweetsByMe()
Status.getOriginal()
public java.util.List<Status> getRetweetsOfMe()
public java.lang.String getScreenName()
Will call Twitter to find out if null but oauth is set.
getSelf()
public java.lang.String getScreenNameIfKnown()
getScreenName()
except this won't ever do
an API call.getScreenName()
public User getSelf()
This will cache the result if it makes an API call.
public Status getStatus() throws TwitterException
TwitterException
Minor Warning: There can be a very slight delay in Twitter for a status-update
to take effect (i.e. for the tweet to become visible). Which means if you have
*just* called updateStatus(), then getStatus() may not match.
public Status getStatus(java.lang.Number id) throws TwitterException
id
- The numerical ID of the status you're trying to retrieve.TwitterException
public Status getStatus(java.lang.String username) throws TwitterException
Warning: this can be null if the user has been doing enough new-style retweets. This is due to flaws in the Twitter API.
TwitterException
public java.io.InputStream getDMImage(Message msg)
public java.util.List<java.lang.String> getTrends()
public java.util.List<java.lang.String> getTrends(java.lang.Number woeid)
a
- Yahoo Where-on-Earth ID. c.f.
http://developer.yahoo.com/geo/geoplanet/Twitter_Geo.getTrendRegions()
public java.util.Date getUntilDate()
@Deprecated public User getUser(long userId)
Twitter_Users.getUser(long)
@Deprecated public User getUser(java.lang.String screenName)
Twitter_Users.getUser(String)
public java.util.List<Status> getUserTimeline() throws TwitterException
TwitterException
public java.util.List<Status> getUserTimeline(java.lang.Long userId) throws TwitterException
getUserTimeline(String)
, but takes a numeric
user-id instead of a screen-name.userId
- TwitterException
public java.util.List<Status> getUserTimeline(java.lang.String screenName) throws TwitterException
This will return 20 results by default, though
setMaxResults(int)
can be used to fetch multiple pages, or
setUntilId(Number)
can be used to page backwards.
Note that if you exclude new-style retweets (via
setIncludeRTs(boolean)
) then this can return less than 20
results -- it can even return none if the latest 20 are all retweets.
There is a cap of 3200 tweets - this is the farthest back you can go down a user timeline!
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.TwitterException.E401
- if the user has protected their tweets, and you do not have
access.TwitterException.SuspendedUser
- if the user has been suspendedTwitterException
public java.util.List<Status> getUserTimelineWithRetweets(java.lang.String screenName) throws TwitterException
setIncludeRTs(boolean)
instead to control
retweet behaviour.
Returns the most recent statuses posted by the given user.
Unlike getUserTimeline(String)
, this includes
new-style retweets.
This will return 20 by default, though
setMaxResults(int)
can be used to fetch multiple
pages. There is a cap of 3200 tweets - this is the farthest
back you can go down a user timeline!
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.TwitterException
@Deprecated public boolean isFollower(java.lang.String userB)
Twitter_Users.isFollower(String)
public boolean isFollower(java.lang.String followerScreenName, java.lang.String followedScreenName)
Twitter_Users.isFollower(String, String)
@Deprecated public boolean isFollowing(java.lang.String userB)
Twitter_Users.isFollowing(String)
@Deprecated public boolean isFollowing(User user)
Twitter_Users.isFollowing(User)
public boolean isRateLimited(Twitter.KRequestType reqType, int minCalls)
type
- minCalls
- Standard value = 1. The minimum number of calls which should
be available.for more info
,
for guaranteed up-to-date info
public boolean isTwitlongerSetup()
TwitLonger
Keeping for backwards compatibility until Q2 2013setupTwitlonger(String, String)
has been used to
provide twitlonger.com details.#updateLongStatus(String, long)
public boolean isValidLogin()
which returns user info
public void reportSpam(java.lang.String screenName)
screenName
- public Status retweet(Status tweet)
tweet
- Note: you cannot retweet your own tweets.public void enableAppAuth(java.lang.String key, java.lang.String secret)
key
- The application keysecret
- The application secretpublic void enableAppAuth(java.lang.String token)
token
- The bearer tokenpublic java.math.BigInteger registerWebhook(java.lang.String webhookUrl, java.lang.String envName) throws java.lang.Exception
webhookUrl
- envName
- java.lang.Exception
public void unregisterWebhook(java.math.BigInteger webhookId, java.lang.String envName) throws TwitterException
webhookId
- The numeric ID of the webhook to deleteenvName
- The name of the environment to remove the webhook fromTwitterException
public void subscribeAccountActivity(java.lang.String envName)
envName
- public void unsubscribeAccountActivity(java.lang.String envName) throws TwitterException
envName
- TwitterException
public java.lang.Integer countAccountActivitySubscriptions(java.lang.String envName)
envName
- public java.util.List<Webhooks.Subscription> listAccountActivitySubscriptions(java.lang.String envName) throws TwitterException, java.lang.IllegalStateException
envName
- TwitterException
java.lang.IllegalStateException
- If called without first providing either an app key/secret or bearer tokenpublic Webhooks.WebhookList getWebhooks() throws TwitterException, java.lang.IllegalStateException
TwitterException
java.lang.IllegalStateException
- If called without first providing either an app key/secret or bearer tokenpublic Status retweetWithComment(Status tweet, java.lang.String comment)
tweet
- comment
- This must be 116 characters or less, as the retweet counts like a url (which, technically, is what it is here).public java.util.List<Status> search(java.lang.String searchTerm)
search(String, ICallback, int)
with no callback and fetching one
pages worth of results.public java.util.List<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 users().show() with the screen names.
This supports maxResults
and pagination. A language filter can
be set via setLanguage(String)
Location can be set via
setSearchLocation(double, double, String)
Other advanced search features can be done via the query string. E.g.
"from:winterstein" - tweets from user winterstein
"to:winterstein" - tweets start with @winterstein
"source:jtwitter" - originating from the application JTwitter - your
query must also must contain at least one keyword parameter.
"filter:links" - tweets contain a link
"apples OR pears" - or ("apples pears" would give you apples and
pears).
searchTerm
- This can include several space-separated keywords, #tags and @username
(for mentions), and use quotes for \"exact phrase\" searches.
Limited to 1,000 characters maximum, including operators.
Queries may additionally be limited by complexity.callback
- an object whose process() method will be called on each new
page of results.rpp
- results per page. 100 is the defaultsetMaxResults(int)
to use > 100.TwitterException.E403
- or E406 if the search query can't be handled.@Deprecated public java.util.List<User> searchUsers(java.lang.String searchTerm)
Twitter_Users.searchUsers(String)
public Message sendMessage(java.lang.String recipientId, java.lang.String text) throws TwitterException
recipientId
- Required. The screen name of the recipient user. This does *not* start with an "@".text
- Required. The text of your direct message. Keep it under 140
characters! This should *not* include the "d username" portionTwitterException.E403
- if the recipient is not following you. (you can \@mention
anyone but you can only dm people who follow you).TwitterException
public void setAPIRootUrl(java.lang.String url)
url
- Format: "http://domain-name", e.g. "http://twitter.com" by
default. Or httpspublic void setCount(java.lang.Integer count)
count
- null for default behaviour. 200 is the current maximum.
Twitter may reject or ignore high counts.public Status setFavorite(Status status, boolean isFavorite)
status
- The status to favorite.
Technical note: Only the ID is needed, so you can use a "fake" Status object here e.g. new Status(id).isFavorite
- public void setIncludeRTs(boolean includeRTs)
includeRTs
- public void setIncludeTweetEntities(boolean tweetEntities)
tweetEntities
- Set to true to enable
Status#getTweetEntities(KEntityType)
, false if you
don't care. Default is true.public void setLanguage(java.lang.String language)
language
- ISO code for language. Can be null for all languages.
Note: there are multiple different ISO codes! Twitter supports ISO 639-1. http://en.wikipedia.org/wiki/ISO_639-1
public 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. Zero is not allowed.
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 setMyLocation(double[] latitudeLongitude)
latitudeLongitude
- Can be null (which is the default), in which case your tweets
will not carry location data.
The valid ranges for latitude is -90.0 to +90.0 (North is positive) inclusive. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive.
which is completely
separate.
public void setSearchLocation(double latitude, double longitude, java.lang.String radius)
search(String)
to tweets by users located within a
given radius of the given latitude/longitude.
The location of a tweet is preferably taken from the Geotagging API, but will fall back to the Twitter profile.
latitude
- longitude
- radius
- E.g. 3.5mi or 2km. Must be <2500kmpublic java.lang.String getSearchLocation()
public void setSearchResultType(java.lang.String resultType)
SEARCH_MIXED
: Include both popular and real time results in the
response.SEARCH_RECENT
: return only the most recent results in
the responseSEARCH_POPULAR
: return only the most popular
results in the response.resultType
- @Deprecated public void setSinceDate(java.util.Date sinceDate)
setSinceId(Number)
for preference.
You can use both constraints together.
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
- setSinceId(Number)
public void setSinceId(java.lang.Number statusId)
If using this, you probably also want to use setUntilId(Number)
.
Twitter returns the most recent results, so this has little effect unless
used with setUntilId().
You may also want to increase setMaxResults(int)
.
statusId
- Can be null. Only a BigInteger really makes sense (although a double would work to some degree
-- but beware of rounding errors).setSinceDate(Date)
public void setSource(java.lang.String sourceApp)
sourceApp
- jtwitterlib by default. Set to null for no source.public 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 140
characters.TwitterException
@Deprecated public void setUntilDate(java.util.Date untilDate)
untilDate
- the untilDate to set. This is NOT
properly supported. It operates by post filtering
results client-side.which is better
public void setUntilId(java.lang.Number untilId)
untilId
- aka max_idpublic java.math.BigInteger getUntilId()
public java.math.BigInteger getSinceId()
public void setExtendedMode(java.lang.Boolean extendedMode)
extendedMode
- public void setAutoPopulateReplyMetadata(java.lang.Boolean autoPopulateReplyMetadata)
extendedMode
- public void setupTwitlonger(java.lang.String twitlongerAppName, java.lang.String twitlongerApiKey)
TwitLonger
Keeping for backwards compatibility until Q2 2013
Set this to allow the use of twitlonger via
#updateLongStatus(String, long)
. To get an api-key for your app,
contact twitlonger as described here: http://www.twitlonger.com/api
This method will be removed June 2013twitlongerAppName
- twitlongerApiKey
- @Deprecated public User show(java.lang.Number userId)
This method will be removed June 2013
@Deprecated public User show(java.lang.String screenName) throws TwitterException, TwitterException.SuspendedUser
TwitterException
TwitterException.SuspendedUser
Twitter_Users.show(String)
public java.util.List<java.lang.String> splitMessage(java.lang.String longStatus)
setStatus(String)
or sendMessage(String, String)
.longStatus
- @Deprecated public User stopFollowing(java.lang.String username)
This method will be removed June 2013
@Deprecated public User stopFollowing(User user)
This method will be removed June 2013
public boolean updateConfiguration()
public Status updateLongStatus(java.lang.String message, java.lang.Number inReplyToStatusId)
TwitLonger
Keeping for backwards compatibility until Q2 2013
Use twitlonger.com to post a lengthy tweet. See twitlonger.com for more
details on their service.
Note: You need to have called setupTwitlonger(String, String)
before calling this.
message
- inReplyToStatusId
- Can be null if this isn't a replysetupTwitlonger(String, String)
public Status updateStatus(java.lang.String statusText)
statusText
- The text of your status update. Must not be more than 140 characters.public static int countCharacters(java.lang.String statusText)
statusText
- The status to checkpublic Status updateStatus(java.lang.String statusText, java.lang.Number inReplyToStatusId) throws TwitterException
updateStatus(String, Number, List)
statusText
- inReplyToStatusId
- TwitterException
public Status updateStatus(java.lang.String statusText, java.lang.Number inReplyToStatusId, java.util.List<java.lang.Number> excludeReplyIds)
statusText
- The text of your status update. Must not be more than 140
characters (with urls counting as 20 or 21 for https).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 Twitter to
agree to mark the tweet as a reply. null to leave this
unset.excludeReplyIds
- A list of numeric user IDs (not @handles) tagged into the
previous tweet in the thread who should NOT be tagged into this
reply.Warning: the microformat for direct messages is supported. BUT: the return value from this method will be null, and not the direct message. Other microformats (such as follow) may result in an exception being thrown.
TwitterException
- if something goes wrong. There is a rare (but not rare
enough) bug whereby Twitter occasionally returns a success
code but the wrong tweet. If this happens, the update may or
may not have worked - wait a bit & check.public Status updateStatusWithVideo(java.lang.String text, java.io.File video)
uploadVideo(File)
+ updateStatusWithUploadedMedia(String, BigInteger, List)
text
- video
- public Status updateStatusWithMedia(java.lang.String statusText, java.math.BigInteger inReplyToStatusId, java.util.List<java.lang.Number> excludedIds, java.io.File mediaFile)
statusText
- inReplyToStatusId
- Can be null.excludedIds
- Untag these users (numeric user IDs) from replymediaFile
- PHOTO_SIZE_LIMIT
public Status updateStatusWithMedia(java.lang.String statusText, java.math.BigInteger inReplyToStatusId, java.io.File mediaFile)
statusText
- inReplyToStatusId
- mediaFile
- public Status updateStatusWithMedia(java.lang.String statusText, java.math.BigInteger inReplyToStatusId, java.util.List<java.lang.Number> excludedIds, java.util.List<java.io.File> mediaFiles)
statusText
- inReplyToStatusId
- Can be null.excludedIds
- Untag these users (numeric user IDs) from replymediaFiles
- PHOTO_SIZE_LIMIT
public Status updateStatusWithMedia(java.lang.String statusText, java.math.BigInteger inReplyToStatusId, java.util.List<java.io.File> mediaFiles)
updateStatusWithMedia(String, BigInteger, List, List
statusText
- inReplyToStatusId
- mediaFiles
- public java.lang.String uploadVideo(java.io.File video)
video
- public java.lang.String uploadVideo(java.io.File video, java.lang.String mimeType, boolean async)
video
- public Status updateStatusWithUploadedMedia(java.lang.String statusText, java.math.BigInteger inReplyToStatusId, java.util.List<java.lang.Number> excludedIds, java.util.List<java.lang.String> mediaFileIds)
statusText
- inReplyToStatusId
- Can be nullexcludedIds
- Untag these users (numeric user IDs) from replymediaFileIds
- As returned by #uploadVideo(File, String)
public Status updateStatusWithUploadedMedia(java.lang.String statusText, java.math.BigInteger inReplyToStatusId, java.util.List<java.lang.String> mediaFileIds)
updateStatusWithUploadedMedia(String, BigInteger, List, List
statusText
- inReplyToStatusId
- mediaFileIds
- public Twitter_Users users()
Note: this is a new object with an unset cursor.
public void setSearchLocation(com.winterwell.jgeoplanet.IPlace place)
place
- Can be null (switches off geo-filtering)public boolean isRateLimited(java.lang.String apiResourceName, boolean defaultIfUnset)
apiResourceName
- defaultIfUnset
- If the answer is not known, return this value.
ie. true for conservative behaviour (beware of never getting data), false for optimistic behaviour.