Title: | R Based Twitter Client |
---|---|
Description: | Provides an interface to the Twitter web API. |
Authors: | Jeff Gentry <[email protected]> |
Maintainer: | Jeff Gentry <[email protected]> |
License: | Artistic-2.0 |
Version: | 1.1.9 |
Built: | 2024-10-29 05:01:31 UTC |
Source: | https://github.com/geoffjentry/twitter |
Will expand a URL that has been processed by a link shortener (e.g. bit.ly). Provided as a convenience function to users who may which to perform this operation.
decode_short_url(url, ...)
decode_short_url(url, ...)
url |
A character string, the URL to decode |
... |
Optional arguments to pass along to RCurl |
Uses the longapi.org API
A character string containing either the original URL (if not shortened) or the full URL (if shortened)
Neil Jang
## Not run: decode_short_url("http://bit.ly/23226se656") ## End(Not run)
## Not run: decode_short_url("http://bit.ly/23226se656") ## End(Not run)
Provides a model representing direct messages (DMs) from Twitter
The directMessage
class is implemented as a reference class.
As there should be no backwards compatibility issues, there are no S4
methods provided as with the user
and status
classes.
An instance of a generator for this class is provided as a convenience
to the user as it is configured to handle most standard cases. To
access this generator, use the object dmFactory
. Accessor set
& get methods are provided for every field using reference class
$accessors()
methodology (see setRefClass
for
more details). As an example, the sender
field could be
accessed using object$getSender()
and object$setSender()
.
The constructor of this object assumes that the user is passing in a JSON encoded Twitter Direct Message. It is also possible to directly pass in the arguments.
text
:Text of the DM
recipient
:A user
object representing the
recipient of the message
recipientSN
:Screen name of the recipient
recipientID
:ID number of the recipient
sender
:A user
object representing the sender
of the message
senderSN
:Screen name of the sender
senderID
:ID number of the sender
created
:When the messages was created
destroy
:Deletes this DM from Twitter. A wrapper
around dmDestroy
toDataFrame
:Converts this into a one row
data.frame
, with each field representing a column.
This can also be accomplished by the S4 style
as.data.frame(objectName)
.
Jeff Gentry
dmGet
, dmSend
, dmDestroy
, setRefClass
## Not run: dm <- dmFactory$new(text='foo', recipientSN='blah') dm$getText() ## assume 'json' is the return from a Twitter call dm <- dmFactory$new(json) dm$getSenderID() ## End(Not run)
## Not run: dm <- dmFactory$new(text='foo', recipientSN='blah') dm$getText() ## assume 'json' is the return from a Twitter call dm <- dmFactory$new(json) dm$getSenderID() ## End(Not run)
These functions allow you to interact with, send, and delete direct messages (DMs) in Twitter.
dmGet(n=25, sinceID=NULL, maxID=NULL, ...) dmSent(n=25, sinceID=NULL, maxID=NULL, ...) dmDestroy(dm, ...) dmSend(text, user, ...)
dmGet(n=25, sinceID=NULL, maxID=NULL, ...) dmSent(n=25, sinceID=NULL, maxID=NULL, ...) dmDestroy(dm, ...) dmSend(text, user, ...)
text |
The text of a message to send |
user |
The user to send a message to, either |
dm |
The message to delete, an object of class |
n |
The maximum number of direct messages to return |
sinceID |
If not |
maxID |
If not |
... |
Further arguments to pass along the communication chain |
These functions will not work without OAuth
authentication
The dmGet
and dmSent
functions will return a list of
directMessage
objects. The former will retrieve DMs
sent to the user while the latter retrieves messages sent from the user.
The dmDestroy
function takes a directMessage
object (perhaps from either dmGet
or dmSent
) and will
delete it from the Twitter server.
The dmSend
function will send a message to another Twitter user.
Jeff Gentry
directMessage
, registerTwitterOAuth
## Not run: dms <- dmGet() dms ## delete the first one dms[[1]]$destroy() dmDestroy(dms[[2]]) ## send a DM dmSend('Testing out twitteR!', 'twitter') ## End(Not run)
## Not run: dms <- dmGet() dms ## delete the first one dms[[1]]$destroy() dmDestroy(dms[[2]]) ## send a DM dmSend('Testing out twitteR!', 'twitter') ## End(Not run)
Returns the n most recently favorited tweets from the specified user.
favorites(user, n = 20, max_id = NULL, since_id = NULL, ...)
favorites(user, n = 20, max_id = NULL, since_id = NULL, ...)
user |
The Twitter user to detail, can be |
n |
Number of tweets to retrieve, up to a maximum of 200 |
max_id |
Maximum ID to search for |
since_id |
Minimum ID to search for |
... |
Optional arguments to pass along to RCurl |
A list of link{status}
objects corresponding to the n
most recent tweets
Jeff Gentry
https://dev.twitter.com/rest/reference/get/favorites/list
## Not run: fav = favorites("barackobama", n=100) ## End(Not run)
## Not run: fav = favorites("barackobama", n=100) ## End(Not run)
This function will accept a list of other Twitter users and will detail if they follow you and/or you follow them.
friendships(screen_names = character(), user_ids = character(), ...)
friendships(screen_names = character(), user_ids = character(), ...)
screen_names |
A vector of one or more Twitter screen names |
user_ids |
A vector of one or more Twitter user id values |
... |
Any other arguments to pass to RCurl |
The combined number of screen names and user ids may not exceed 100. Any non-existent users will be dropped from the output
A data.frame, one row for each user requested with columns name
,
screen_name
, id
, following
and followed_by
. The
latter two columns will be TRUE
or FALSE
depending on that user's
relations with your account.
Jeff Gentry
https://dev.twitter.com/docs/api/1.1/get/friendships/lookup
## Not run: friendships() ## End(Not run)
## Not run: friendships() ## End(Not run)
Given a registered database backend which contains a table of tweets, will return the ID of the most recent tweet stored in that table
get_latest_tweet_id(table_name = "tweets")
get_latest_tweet_id(table_name = "tweets")
table_name |
The name of the table in the database containing tweets |
A wrapper around a select max(id)
on the table_name
The ID of the most recent tweet in the table, or a stop
if the table is empty
Jeff Gentry
## Not run: register_sqlite_backend("sqlit_file") get_latest_tweet_id("rstats_tweets") ## End(Not run)
## Not run: register_sqlite_backend("sqlit_file") get_latest_tweet_id("rstats_tweets") ## End(Not run)
Will retrieve the current rate limit information for the authenticated user, displayed as a data.frame displaying specifc information for every Twitter resource
getCurRateLimitInfo(resources=resource_families, ...)
getCurRateLimitInfo(resources=resource_families, ...)
resources |
A character vector of specific resources to get information for |
... |
Optional arguments to pass to cURL |
By default, all known resource families will be polled. These families are contained
in the object resource_families
. If you would like to filter this down you
may tweak the resources
argument.
The full list of allowed values in resources
is as follows: lists
,
application
, friendships
, blocks
, geo
, users
,
followers
, statuses
, help
, friends
, direct_messages
,
account
, favorites
, saved_searches
, search
, trends
.
A four column data.frame with columns resource
, limit
, remaining
and reset
. These detail the specific resource name, the rate limit for that block,
the number of calls remaining and the time the rate limit will be reset in UTC time.
Jeff Gentry
## Not run: zz <- getCurRateLimitInfo(c("lists", "users")) ## End(Not run)
## Not run: zz <- getCurRateLimitInfo(c("lists", "users")) ## End(Not run)
These functions will allow you to interact with the trend portion of the Twitter API
availableTrendLocations(...) closestTrendLocations(lat, long, ...) getTrends(woeid, exclude=NULL, ...)
availableTrendLocations(...) closestTrendLocations(lat, long, ...) getTrends(woeid, exclude=NULL, ...)
woeid |
A numerical identification code describing a location, a Yahoo! Where On Earth ID |
lat |
A numerical latitude value, between -180 and 180 inclusive. West is negative, East is positive |
long |
A numerical longitude value, between -180 and 180 inclusive. South is negative, North is positive |
exclude |
If set to |
... |
Additional arguments to be passed to RCurl |
The availableTrendLocations
and closestTrendLocations
functions will return a
data.frame with three columns - name
, country
and woeid
. The closestTrendLocations
function will return the locations closest to the specified latitude and longitude.
The getTrends
function takes a specified woeid and returns the trending topics associated
with that woeid. It returns a data.frame with the columns being name
, url
,
promoted_content
, query
and woeid
- one row per trend.
A data.frame with the columns specified in Details
above
Jeff Gentry
## Not run: woeid = availableTrendLocations[1, "woeid"] t1 <- getTrends(woeid) ## End(Not run)
## Not run: woeid = availableTrendLocations[1, "woeid"] t1 <- getTrends(woeid) ## End(Not run)
These functions allow you interact with information about a Twitter user - retrieving their base information, list of friends, list of followers, and an up to date timeline.
getUser(user, ...) lookupUsers(users, includeNA=FALSE, ...)
getUser(user, ...) lookupUsers(users, includeNA=FALSE, ...)
user |
The Twitter user to detail, can be |
users |
A vector of either user IDs or screen names or a mix of both |
includeNA |
If |
... |
Optional arguments to be passed to |
These functions will only return fully formed objects if the authenticated user is allowed to see the requested user. If that person has a private account and has not allowed you to see them, you will not be able to extract that information.
The lookupUsers
function should be used in cases where there are
multiple lookups going to take place, to reduce the API call load. This function
requires OAuth authentication.
The getUser
function returns an object of class
user
.
The lookupUsers
function will return a list of user
objects,
sorted in the order of the users
argument, with names being the particular
element of users
that it matches to. If the includeNA
argument is set
to FALSE
(default), any non-existing users will be dropped from the list.
Jeff Gentry
## Not run: tuser <- getUser('geoffjentry') users <- lookupUsers(c('geoffjentry', 'whitehouse')) ## End(Not run)
## Not run: tuser <- getUser('geoffjentry') users <- lookupUsers(c('geoffjentry', 'whitehouse')) ## End(Not run)
Functions designed to import data into twitteR objects from a variety of data sources. Currently only JSON is supported, and this entire branch of functionality should be considered experimental & under development.
import_statuses(raw_data, conversion_func = json_to_statuses) import_trends(raw_data, conversion_func = json_to_trends) import_users(raw_data, conversion_func = json_to_users) import_obj(raw_data, conversion_func, ...) json_to_users(raw_data) json_to_statuses(raw_data) json_to_trends(raw_data)
import_statuses(raw_data, conversion_func = json_to_statuses) import_trends(raw_data, conversion_func = json_to_trends) import_users(raw_data, conversion_func = json_to_users) import_obj(raw_data, conversion_func, ...) json_to_users(raw_data) json_to_statuses(raw_data) json_to_trends(raw_data)
raw_data |
Data to be be parsed via the prescribed function |
conversion_func |
The function to convert |
... |
Arguments to pass along to |
A list of twitteR objects of the appropriate type, e.g. status
, user
, etc
Jeff Gentry
## Not run: status_list = import_statuses(list_of_status_json) ## End(Not run)
## Not run: status_list = import_statuses(list_of_status_json) ## End(Not run)
These functions allow a user to store twitteR based data to a database backend as well as retrieving previously stored data
store_tweets_db(tweets, table_name="tweets") store_users_db(users, table_name="users") load_users_db(as.data.frame = FALSE, table_name = "users") load_tweets_db(as.data.frame = FALSE, table_name = "tweets")
store_tweets_db(tweets, table_name="tweets") store_users_db(users, table_name="users") load_users_db(as.data.frame = FALSE, table_name = "users") load_tweets_db(as.data.frame = FALSE, table_name = "tweets")
tweets |
A list of |
users |
A list of |
as.data.frame |
if |
table_name |
The database table to use for storing and loading |
store_tweets_db
and store_users_db
return TRUE
of FALSE
based on their success or not. The loading functions return either a data.frame
of the data (representing the underlying table) or a list of the appropriate twitteR
objects.
Jeff Gentry
register_db_backend
, register_sqlite_backend
, register_mysql_backend
## Not run: register_sqlite_backend("/path/to/sqlite/file") tweets = searchTwitter("#scala") store_tweets_db(tweets) from_db = load_tweets_db() ## End(Not run)
## Not run: register_sqlite_backend("/path/to/sqlite/file") tweets = searchTwitter("#scala") store_tweets_db(tweets) from_db = load_tweets_db() ## End(Not run)
twitteR can have a database backend registered from which to store and load tweet and user data. These functions provide mechanisms for setting up the connection within twitteR
register_db_backend(db_handle) register_sqlite_backend(sqlite_file, ...) register_mysql_backend(db_name, host, user, password, ...)
register_db_backend(db_handle) register_sqlite_backend(sqlite_file, ...) register_mysql_backend(db_name, host, user, password, ...)
db_handle |
A DBI connection |
sqlite_file |
File path for a SQLite file |
db_name |
Name of the database to connect to |
host |
Hostname the database is on |
user |
username to connect to the database with |
password |
password to connect to the database with |
... |
extra arguments to pass to |
Currently only RSQLite
and RMySQL
are supported. To use either
of these DBI implementations the appropriate packages will need to be
installed.
The register_sqlite_backend
and register_mysql_backend
are
convenience wrappers to both create the DBI connection and call register_db_backend
for you.
The DBI connection, invisibly
Jeff Gentry
store_tweets_db
, store_users_db
, load_tweets_db
, load_users_db
## Not run: register_sqlite_backend("/path/to/sqlite/file") tweets = searchTwitter("#scala") store_tweets_db(tweets) from_db = load_tweets_db() ## End(Not run)
## Not run: register_sqlite_backend("/path/to/sqlite/file") tweets = searchTwitter("#scala") store_tweets_db(tweets) from_db = load_tweets_db() ## End(Not run)
These functions are deprecated
getTwitterOAuth(consumer_key, consumer_secret) registerTwitterOAuth(oauth)
getTwitterOAuth(consumer_key, consumer_secret) registerTwitterOAuth(oauth)
consumer_key |
The consumer key supplied by Twitter |
consumer_secret |
The consumer secret supplied by Twitter |
oauth |
An object of class |
These functions are deprecated, see setup_twitter_oauth
TRUE
on success, otherwise an error will be thrown
Jeff Gentry
setup_twitter_oauth
## Not run: fakeExample = 5 ## End(Not run)
## Not run: fakeExample = 5 ## End(Not run)
These functions can be used to return retweets or users who retweeted a tweet
retweets(id, n = 20, ...)
retweets(id, n = 20, ...)
id |
The ID of the tweet to get retweet information on |
n |
The number of results to return, up to 100 |
... |
Further arguments to pass on to httr |
For retweets
the n most recent retweets of the original tweet.
For retweeters
the n most recent users who have retweeted this tweet.
Jeff Gentry
## Not run: retweets("21947795900469248") st = showStatus("21947795900469248") retweeters(st$getId()) ## End(Not run)
## Not run: retweets("21947795900469248") st = showStatus("21947795900469248") retweeters(st$getId()) ## End(Not run)
A convenience function designed to wrap the process of running a twitter search and pushing the results to a database. If this is called more than once, the search will start with the most recent tweet already stored.
search_twitter_and_store(searchString, table_name = "tweets", lang = NULL, locale = NULL, geocode = NULL, retryOnRateLimit = 120, ...)
search_twitter_and_store(searchString, table_name = "tweets", lang = NULL, locale = NULL, geocode = NULL, retryOnRateLimit = 120, ...)
searchString |
The search string to use, e.g. as one would in |
table_name |
The database to store the tweets to, see |
lang |
If not |
locale |
If not |
geocode |
If not |
retryOnRateLimit |
If non-zero the search command will block retry up to X times if the rate limit is experienced. This might lead to a much longer run time but the task will eventually complete if the retry count is high enough |
... |
Optional arguments to be passed to |
All arguments but table_name
are being passed directly to searchTwitter
.
This function will check if table_name
exists, and if so will also use a sinceID
of the
most recent ID in the table. The search is performed, the returned tweets are stored
in the database via store_tweets_db
.
The number of tweets stored
Jeff Gentry
register_db_backend
, searchTwitter
, store_tweets_db
## Not run: register_sqlite_backend("sqlit_file") n = search_twitter_and_store("#rstats", "rstats_tweets") ## End(Not run)
## Not run: register_sqlite_backend("sqlit_file") n = search_twitter_and_store("#rstats", "rstats_tweets") ## End(Not run)
This function will issue a search of Twitter based on a supplied search string.
searchTwitter(searchString, n=25, lang=NULL, since=NULL, until=NULL, locale=NULL, geocode=NULL, sinceID=NULL, maxID=NULL, resultType=NULL, retryOnRateLimit=120, ...) Rtweets(n=25, lang=NULL, since=NULL, ...)
searchTwitter(searchString, n=25, lang=NULL, since=NULL, until=NULL, locale=NULL, geocode=NULL, sinceID=NULL, maxID=NULL, resultType=NULL, retryOnRateLimit=120, ...) Rtweets(n=25, lang=NULL, since=NULL, ...)
searchString |
Search query to issue to twitter. Use "+" to separate query terms. |
n |
The maximum number of tweets to return |
lang |
If not |
since |
If not |
until |
If not |
locale |
If not |
geocode |
If not |
sinceID |
If not |
maxID |
If not |
resultType |
If not |
retryOnRateLimit |
If non-zero the search command will block retry up to X times if the rate limit is experienced. This might lead to a much longer run time but the task will eventually complete if the retry count is high enough |
... |
Optional arguments to be passed to |
These commands will return any authorized tweets which match the
search criteria. Note that there are pagination restrictions as well
as other limits on what can be searched, so it is always possible to
not retrieve as many tweets as was requested with the n
argument. Authorized tweets are public tweets as well as those
protected tweets that are available to the user after authenticating
via registerTwitterOAuth
.
The searchString
is always required. Terms can contain spaces,
and multiple terms should be separated with "+".
For the geocode
argument, the values are given in the format
latitude,longitude,radius
, where the radius can have either
mi
(miles) or km
(kilometers) as a unit. For example
geocode='37.781157,-122.39720,1mi'
.
For the sinceID
argument, if the requested ID value is older
than the oldest available tweets, the API will return tweets starting
from the oldest ID available.
For the maxID
argument, tweets upto this ID value will be returned
starting from the oldest ID available. Useful for paging.
The resultType
argument specifies the type of search results received
in API response. Default is mixed
.
Allowed values are mixed
(includes popular + real time results),
recent
(returns the most recent results) and popular
(returns only the most popular results).
The Rtweets
function is a wrapper around searchTwitter
which hardcodes in a search for #rstats
.
A list of status
objects
Jeff Gentry
## Not run: searchTwitter("#beer", n=100) Rtweets(n=37) ## Search between two dates searchTwitter('charlie sheen', since='2011-03-01', until='2011-03-02') ## geocoded results searchTwitter('patriots', geocode='42.375,-71.1061111,10mi') ## using resultType searchTwitter('world cup+brazil', resultType="popular", n=15) searchTwitter('from:hadleywickham', resultType="recent", n=10) ## End(Not run)
## Not run: searchTwitter("#beer", n=100) Rtweets(n=37) ## Search between two dates searchTwitter('charlie sheen', since='2011-03-01', until='2011-03-02') ## geocoded results searchTwitter('patriots', geocode='42.375,-71.1061111,10mi') ## using resultType searchTwitter('world cup+brazil', resultType="popular", n=15) searchTwitter('from:hadleywickham', resultType="recent", n=10) ## End(Not run)
This function wraps the OAuth authentication handshake functions from the httr package for a twitteR session
setup_twitter_oauth(consumer_key, consumer_secret, access_token=NULL, access_secret=NULL)
setup_twitter_oauth(consumer_key, consumer_secret, access_token=NULL, access_secret=NULL)
consumer_key |
The consumer key supplied by Twitter |
consumer_secret |
The consumer secret supplied by Twitter |
access_token |
The access token supplied by Twitter |
access_secret |
The access secret supplied by Twitter |
The httr
package can cache authentication. See Token
for
details
If both access_token
and access_secret
are set (i.e. not NULL
),
these will be supplied directly to the OAuth authentication instead of the browser
based authentication dance one would normally experience. This requires you to already
know the access tokens for your Twitter app. The usefuleness of this feature is primarily
in a headless environment where a web browser is not available.
This is called for its side effect
Jeff Gentry
## Not run: setup_twitter_oauth("CONSUMER_KEY", "CONSUMER_SECRET") ## End(Not run)
## Not run: setup_twitter_oauth("CONSUMER_KEY", "CONSUMER_SECRET") ## End(Not run)
These functions can be used to retrieve specific tweets from the server
showStatus(id, ...) lookup_statuses(ids, ...)
showStatus(id, ...) lookup_statuses(ids, ...)
id |
ID of a specific tweet, should be a String, but numbers are accepted |
ids |
A vector of IDs to lookup, should be Strings but numbers are accepted |
... |
Optional arguments to be passed to |
Ideally a POST request would be used for lookup_statuses, however currently there is a problem (issue 78 on github) and GET is used.
For showStatus, an object of class status
For lookup_statuses, a list of status
objects. Note that these will not be in the
same order as the ids
argument and that any id which could not be retrieved will not be present.
Jeff Gentry
## Not run: showStatus('123') lookup_statuses(c("123", "234", "456")) ## End(Not run)
## Not run: showStatus('123') lookup_statuses(c("123", "234", "456")) ## End(Not run)
Container for Twitter status messages, including the text as well as basic information
The status
class is implemented as a reference class. This class
was previously implemented as an S4 class, and for backward
compatibility purposes the old S4 accessor methods have been left in,
although new code should not be written with these. An instance of a
generator for this class is provided as a convenience to the user as
it is configured to handle most standard cases. To access this
generator, use the object statusFactory
. Accessor set & get
methods are provided for every field using reference class
$accessors()
methodology (see setRefClass
for
more details). As an example, the screenName
field could be
accessed using object$getScreenName
and
object$setScreenName
.
The constructor of this object assumes that the user is passing in a JSON encoded Twitter status. It is also possible to directly pass in the arguments.
text
:The text of the status
screenName
:Screen name of the user who posted this status
id
:ID of this status
replyToSN
:Screen name of the user this is in reply to
replyToUID
:ID of the user this was in reply to
statusSource
:Source user agent for this tweet
created
:When this status was created
truncated
:Whether this status was truncated
favorited
:Whether this status has been favorited
retweeted
:TRUE if this status has been retweeted
retweetCount
:The number of times this status has been retweeted
toDataFrame
:Converts this into a one row
data.frame
, with each field representing a column.
This can also be accomplished by the S4 style
as.data.frame(objectName)
.
Jeff Gentry
## Not run: st <- statusFactory$new(screenName="test", text="test message") st$getScreenName() st$getText() ## Assume 'json' is the return from a Twitter call st <- statusFactory$new(json) st$getScreenName() ## End(Not run)
## Not run: st <- statusFactory$new(screenName="test", text="test message") st$getScreenName() st$getText() ## Assume 'json' is the return from a Twitter call st <- statusFactory$new(json) st$getScreenName() ## End(Not run)
Given a list of status objects, will remove retweets from the list to provide a "pure" set of tweets.
strip_retweets(tweets, strip_manual = TRUE, strip_mt = TRUE)
strip_retweets(tweets, strip_manual = TRUE, strip_mt = TRUE)
tweets |
A list of |
strip_manual |
If |
strip_mt |
If |
Newer style retweets are summarily removed regardless of options.
Older style retweets (aka manual retweets) are tweets of the form
RT @user blah blah
. If strip_manual
is TRUE
, tweets
containing the RT
string will have everything including and to the
right of the RT
will be removed. Everything to the left of the
RT
will remain, as this should be original content.
If strip_mt
is TRUE
, tweets will be stripped in the same
manner as strip_manual
but using the string MT
A list of status
objects with retweeted content removed
Jeff Gentry
## Not run: tweets = searchTwitter("stuff") no_retweets = strip_retweets(tweets) ## End(Not run)
## Not run: tweets = searchTwitter("stuff") no_retweets = strip_retweets(tweets) ## End(Not run)
This function will run an R expression and send a direct message to a specified user on success or failure.
taskStatus(expr, to, msg="")
taskStatus(expr, to, msg="")
expr |
An R expression that will be run |
to |
The user to send a message to, either |
msg |
An extra message to append to the standard DM |
This function will run expr
, and send a Direct Message (DM)
upon completion which will report the expression's success or failure.
Either the value of the expression or an object of class
try-error
.
Jeff Gentry
## Not run: taskStatus(z<-5, "username", session=sess) ## End(Not run)
## Not run: taskStatus(z<-5, "username", session=sess) ## End(Not run)
These functions will allow you to retrieve various timelines within the Twitter universe
userTimeline(user, n=20, maxID=NULL, sinceID=NULL, includeRts=FALSE, excludeReplies=FALSE, ...) homeTimeline(n=25, maxID=NULL, sinceID=NULL, ...) mentions(n=25, maxID=NULL, sinceID=NULL, ...) retweetsOfMe(n=25, maxID=NULL, sinceID=NULL, ...) listTimeline(user, list_name, n=20, maxID=NULL, sinceID=NULL, includeRts=FALSE, excludeReplies=FALSE, ...)
userTimeline(user, n=20, maxID=NULL, sinceID=NULL, includeRts=FALSE, excludeReplies=FALSE, ...) homeTimeline(n=25, maxID=NULL, sinceID=NULL, ...) mentions(n=25, maxID=NULL, sinceID=NULL, ...) retweetsOfMe(n=25, maxID=NULL, sinceID=NULL, ...) listTimeline(user, list_name, n=20, maxID=NULL, sinceID=NULL, includeRts=FALSE, excludeReplies=FALSE, ...)
user |
The Twitter user to detail, can be |
n |
Number of tweets to retrieve, up to a maximum of 3200 |
maxID |
Maximum ID to search for |
sinceID |
Minimum (not inclusive) ID to search for |
includeRts |
If |
excludeReplies |
if |
list_name |
Target list name, used for |
... |
Optional arguments to be passed to |
A list of status
objects
Jeff Gentry
## Not run: ut <- userTimeline('barackobama', n=100) ## End(Not run)
## Not run: ut <- userTimeline('barackobama', n=100) ## End(Not run)
This function will take a list of objects from a single twitteR class and return a data.frame version of the members
twListToDF(twList)
twListToDF(twList)
twList |
A list of objects of a single twitteR class, restrictions are listed in |
The classes supported by this function are status
, user
,
and directMessage
.
A data.frame
with rows corresponding to the objects in the list and columns being the
fields of the class
Jeff Gentry
## Not run: zz <- searchTwitter("#rstats") twListToDF(zz) ## End(Not run)
## Not run: zz <- searchTwitter("#rstats") twListToDF(zz) ## End(Not run)
These functions can be used to set or delete a user's Twitter status
tweet(text, ...) updateStatus(text, lat=NULL, long=NULL, placeID=NULL, displayCoords=NULL, inReplyTo=NULL, mediaPath=NULL, bypassCharLimit=FALSE, ...) deleteStatus(status, ...)
tweet(text, ...) updateStatus(text, lat=NULL, long=NULL, placeID=NULL, displayCoords=NULL, inReplyTo=NULL, mediaPath=NULL, bypassCharLimit=FALSE, ...) deleteStatus(status, ...)
text |
The text to use for a new status |
status |
An object of class |
lat |
If not |
long |
If not |
placeID |
If not |
displayCoords |
Whether or not to put a pin on the exact coordinates a tweet has been sent from,
|
inReplyTo |
If not |
mediaPath |
If not |
bypassCharLimit |
If |
... |
Optional arguments to be passed to |
These messages will only operate properly if the user is authenticated
via OAuth
The tweet
and updateStatus
functions are the same.
To delete a status message, pass in an object of class
status
, such as from the return value of updateStatus
.
The updateStatus
function will return an object of class
status
.
The deleteStatus
returns TRUE
on success and an error if
failure occurs.
Jeff Gentry
## Not run: ns <- updateStatus('this is my new status message') ## ooops, we want to remove it! deleteStatus(ns) ## End(Not run)
## Not run: ns <- updateStatus('this is my new status message') ## ooops, we want to remove it! deleteStatus(ns) ## End(Not run)
This function uses an existing httr OAuth Token in the Twitter session
use_oauth_token(twitter_token)
use_oauth_token(twitter_token)
twitter_token |
An httr Token object |
This function is an escape hatch for nonstandard OAuth scenarios. Use setup_twitter_token unless it doesn't work for your use case.
This is called for its side effect
Anand Patil
## Not run: library(httr) library(twitteR) token <- Token2.0$new( params = list(as_header=TRUE), app = oauth_app("fun.with.twitter", "no.key", "no.secret"), endpoint = oauth_endpoints("twitter"), credentials = list(access_token = "AAAAAAAAAAAAAAAAAAA%3DAAAAAAAAAAAAAA"), cache = FALSE ) use_oauth_token(token) ## End(Not run)
## Not run: library(httr) library(twitteR) token <- Token2.0$new( params = list(as_header=TRUE), app = oauth_app("fun.with.twitter", "no.key", "no.secret"), endpoint = oauth_endpoints("twitter"), credentials = list(access_token = "AAAAAAAAAAAAAAAAAAA%3DAAAAAAAAAAAAAA"), cache = FALSE ) use_oauth_token(token) ## End(Not run)
This class is designed to represent a user on Twitter, modeling information available
The user
class is implemented as a reference class. This class
was previously implemented as an S4 class, and for backward
compatibility purposes the old S4 accessor methods have been left in,
although new code should not be written with these. An instance of a
generator for this class is provided as a convenience to the user as
it is configured to handle most standard cases. To access this
generator, use the object userFactory
. Accessor set & get
methods are provided for every field using reference class
$accessors()
methodology (see setRefClass
for
more details). As an example, the screenName
field could be
accessed using object$getScreenName
and
object$setScreenName
.
The constructor of this object assumes that the user is passing in a JSON encoded Twitter user. It is also possible to directly pass in the arguments.
name
:Name of the user
screenName
:Screen name of the user
id
:ID value for this user
lastStatus
:Last status update for the user
description
:User's description
statusesCount
:Number of status updates this user has had
followersCount
:Number of followers for this user
favoritesCount
:Number of favorites for this user
friendsCount
:Number of followees for this user
url
:A URL associated with this user
created
:When this user was created
protected
:Whether or not this user is protected
verified
:Whether or not this user is verified
location
:Location of the user
listedCount
:The number of times this user appears in public lists
followRequestSent
:If authenticated via OAuth, will be TRUE if you've sent a friend request to this user
profileImageUrl
:URL of the user's profile image, if one exists
getFollowerIDs(n=NULL, ...)
:Will return a vector of
twitter user IDs representing followers of this user, up to a
maximum of n
values. If n
is NULL, all followers
will be returned
getFollowers(n=NULL, ...)
:Will return a list of
user
objects representing followers of this user, up to a
maximum of n
values. If n
is NULL, all followers
will be returned
getFriendIDs(n=NULL, ...)
:Will return a vector of
twitter user IDs representing users this user follows, up to a
maximum of n
values. If n
is NULL, all friends
will be returned
getFriends(n=NULL, ...)
:Will return a list of
user
objects representing users this user follows, up to a
maximum of n
values. If n
is NULL, all friendss
will be returned
toDataFrame(row.names=NULL, optional=FALSE)
:Converts
this into a one row
data.frame
, with each field except for
lastStatus
representing a column.
This can also be accomplished by the S4 style
as.data.frame(objectName)
.
Jeff Gentry
## This example is run, but likely not how you want to do things us <- userFactory$new(screenName="test", name="Joe Smith") us$getScreenName() us$getName() ## Not run: ## Assume 'json' is the return from a Twitter call us <- userFactory$new(json) us$getScreenName() ## End(Not run)
## This example is run, but likely not how you want to do things us <- userFactory$new(screenName="test", name="Joe Smith") us$getScreenName() us$getName() ## Not run: ## Assume 'json' is the return from a Twitter call us <- userFactory$new(json) us$getScreenName() ## End(Not run)