Description Usage Arguments Details Value See Also Examples
Returns Twitter statuses matching a user provided search query. ONLY RETURNS DATA FROM THE PAST 6-9 DAYS. To return more than 18,000 statuses in a single call, set "retryonratelimit" to TRUE.
search_tweets2 Passes all arguments to search_tweets. Returns data from one OR MORE search queries.
1 2 3 4 5 |
q |
Query to be searched, used to filter and select tweets to
return from Twitter's REST API. Must be a character string not to
exceed maximum of 500 characters. Spaces behave like boolean
"AND" operator. To search for tweets containing at least one of
multiple possible terms, separate each search term with spaces
and "OR" (in caps). For example, the search |
n |
Integer, specifying the total number of desired tweets to
return. Defaults to 100. Maximum number of tweets returned from a
single token is 18,000. To return more than 18,000 tweets, users
are encouraged to set |
type |
Character string specifying which type of search
results to return from Twitter's REST API. The current default is
|
include_rts |
Logical, indicating whether to include retweets in search results. Retweets are classified as any tweet generated by Twitter's built-in "retweet" (recycle arrows) function. These are distinct from quotes (retweets with additional text provided from sender) or manual retweets (old school method of manually entering "RT" into the text of one's tweets). |
geocode |
Geographical limiter of the template
"latitude,longitude,radius" e.g., |
max_id |
Character string specifying the [oldest] status id
beyond which search results should resume returning. Especially
useful large data returns that require multiple iterations
interrupted by user time constraints. For searches exceeding
18,000 tweets, users are encouraged to take advantage of rtweet's
internal automation procedures for waiting on rate limits by
setting |
parse |
Logical, indicating whether to return parsed
data.frame, if true, or nested list, if false. By default,
|
token |
OAuth token. By default |
retryonratelimit |
Logical indicating whether to wait and retry when rate limited. This argument is only relevant if the desired return (n) exceeds the remaining limit of available requests (assuming no other searches have been conducted in the past 15 minutes, this limit is 18,000 tweets). Defaults to false. Set to TRUE to automate process of conducting big searches (i.e., n > 18000). For many search queries, esp. specific or specialized searches, there won't be more than 18,000 tweets to return. But for broad, generic, or popular topics, the total number of tweets within the REST window of time (7-10 days) can easily reach the millions. |
verbose |
Logical, indicating whether or not to include output
processing/retrieval messages. Defaults to TRUE. For larger
searches, messages include rough estimates for time remaining
between searches. It should be noted, however, that these time
estimates only describe the amount of time between searches and
not the total time remaining. For large searches conducted with
|
... |
Further arguments passed as query parameters in request
sent to Twitter's REST API. To return only English language
tweets, for example, use |
Twitter API documentation recommends limiting searches to 10 keywords and operators. Complex queries may also produce API errors preventing recovery of information related to the query. It should also be noted Twitter's search API does not consist of an index of all Tweets. At the time of searching, the search API index includes between only 6-9 days of Tweets.
Number of tweets returned will often be less than what was
specified by the user. This can happen because (a) the search
query did not return many results (the search pool is already
thinned out from the population of tweets to begin with),
(b) because user hitting rate limit for a given token, or (c)
of recent activity (either more tweets, which affect pagination
in returned results or deletion of tweets). To return more than
18,000 tweets in a single call, users must set
retryonratelimit
argument to true. This method relies on
updating the max_id
parameter and waiting for token rate
limits to refresh between searches. As a result, it is possible
to search for 50,000, 100,000, or even 10,000,000 tweets, but
these searches can take hours or even days. At these durations,
it would not be uncommon for connections to timeout. Users are
instead encouraged to breakup data retrieval into smaller chunks
by leveraging retryonratelimit
and then using the
status_id of the oldest tweet as the max_id
to resume
searching where the previous efforts left off.
List object with tweets and users each returned as a data frame.
A tbl data frame with additional "query" column.
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets
Other tweets: get_favorites
,
get_mentions
, get_timeline
,
lists_statuses
,
lookup_statuses
, tweets_data
,
tweets_with_users
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ## Not run:
## search for 1000 tweets mentioning Hillary Clinton
hrc <- search_tweets(q = "hillaryclinton", n = 1000)
## data frame where each observation (row) is a different tweet
hrc
## users data also retrieved. can access it via users_data()
users_data(hrc)
## search for 1000 tweets in English
djt <- search_tweets(q = "realdonaldtrump", n = 1000, lang = "en")
## preview tweets data
djt
## preview users data
users_data(djt)
## exclude retweets
rt <- search_tweets("rstats", n = 500, include_rts = FALSE)
## perform search for lots of tweets
rt <- search_tweets(
"trump OR president OR potus", n = 100000,
retryonratelimit = TRUE
)
## plot time series of tweets frequency
ts_plot(rt, by = "mins")
## make multiple independent search queries
ds <- Map(
"search_tweets",
c("\"data science\"", "rstats OR python"),
n = 1000
)
## bind by row whilst preserving users data
ds <- do_call_rbind(ds)
## preview tweets data
ds
## preview users data
users_data(ds)
## End(Not run)
## Not run:
## search using multilple queries
st2 <- search_tweets2(
c("\"data science\"", "rstats OR python"),
n = 500
)
## preview tweets data
st2
## preview users data
users_data(st2)
## check breakdown of results by search query
table(st2$query)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.