Skip to content

Commit

Permalink
version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
llrs authored and cran-robot committed Jan 9, 2023
1 parent 137a2df commit f6ffa1a
Show file tree
Hide file tree
Showing 337 changed files with 4,503 additions and 86,679 deletions.
22 changes: 11 additions & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Type: Package
Package: rtweet
Title: Collecting Twitter Data
Version: 1.0.2
Version: 1.1.0
Authors@R: c(
person("Michael W.", "Kearney", , "kearneymw@missouri.edu", role = c("aut"),
person("Michael W.", "Kearney", , "kearneymw@missouri.edu", role = "aut",
comment = c(ORCID = "0000-0002-0730-4694")),
person("Lluís", "Revilla Sancho", , "lluis.revilla@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9747-2570")),
Expand All @@ -24,21 +24,21 @@ URL: https://docs.ropensci.org/rtweet/,
https://github.com/ropensci/rtweet/
BugReports: https://github.com/ropensci/rtweet/issues
Depends: R (>= 4.0.0)
Imports: bit64 (>= 4.0.5), curl (>= 4.3.2), httr (>= 1.3.0), jsonlite
(>= 0.9.22), lifecycle (>= 1.0.0), methods, progress (>=
1.2.2), rlang (>= 0.4.10), tibble (>= 1.3.4), utils, withr (>=
2.5.0)
Imports: bit64 (>= 4.0.5), curl (>= 4.3.2), httr (>= 1.3.0), httr2 (>=
0.2.2), jsonlite (>= 0.9.22), lifecycle (>= 1.0.0), methods,
progress (>= 1.2.2), rlang (>= 0.4.10), tibble (>= 1.3.4),
utils, withr (>= 2.5.0)
Suggests: askpass (>= 1.1), covr (>= 3.5.1), dplyr (>= 1.0.9), ggplot2
(>= 3.3.5), httpuv (>= 1.6.5), igraph (>= 1.3.2), knitr (>=
1.39), magick (>= 2.7.3), maps (>= 3.4.0), openssl (>= 2.0.2),
rappdirs (>= 0.3.3), rmarkdown (>= 2.14), testthat (>= 3.1.0),
vcr (>= 0.6.0), webshot (>= 0.5.3)
rmarkdown (>= 2.14), testthat (>= 3.1.0), vcr (>= 0.6.0),
webshot (>= 0.5.3)
VignetteBuilder: knitr
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.2.1
RoxygenNote: 7.2.2
NeedsCompilation: no
Packaged: 2022-07-21 08:45:08 UTC; lluis
Packaged: 2023-01-08 16:20:38 UTC; lluis
Author: Michael W. Kearney [aut] (<https://orcid.org/0000-0002-0730-4694>),
Lluís Revilla Sancho [aut, cre]
(<https://orcid.org/0000-0001-9747-2570>),
Expand All @@ -48,4 +48,4 @@ Author: Michael W. Kearney [aut] (<https://orcid.org/0000-0002-0730-4694>),
Jonathan Sidi [ctb] (<https://orcid.org/0000-0002-4222-1819>)
Maintainer: Lluís Revilla Sancho <lluis.revilla@gmail.com>
Repository: CRAN
Date/Publication: 2022-07-21 09:30:02 UTC
Date/Publication: 2023-01-09 08:50:02 UTC
427 changes: 230 additions & 197 deletions MD5

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# Generated by roxygen2: do not edit by hand

S3method("[",rtweet_screen_name)
S3method("[",tweets)
S3method("[",users)
S3method(entity,default)
S3method(entity,tweets)
S3method(ids,default)
S3method(ids,followers)
S3method(ids,friends)
S3method(ids,post_tweet)
S3method(ids,rules)
S3method(ids,tweets)
S3method(ids,users)
S3method(print,post_tweet)
S3method(print,rtweet_bearer)
S3method(print,rtweet_screen_name)
S3method(print,tweet_deleted)
S3method(print,tweets)
S3method(print,users)
S3method(rbind,tweets)
S3method(rbind,users)
S3method(round_time,Date)
S3method(round_time,POSIXt)
S3method(rules,rules)
export(as_screenname)
export(as_userid)
export(auth_as)
Expand All @@ -15,11 +33,14 @@ export(auth_save)
export(auth_setup_default)
export(auth_sitrep)
export(bearer_token)
export(clean_tweets)
export(create_token)
export(direct_messages)
export(direct_messages_received)
export(direct_messages_sent)
export(do_call_rbind)
export(entity)
export(filtered_stream)
export(flatten)
export(get_collections)
export(get_favorites)
Expand All @@ -34,6 +55,7 @@ export(get_timelines)
export(get_token)
export(get_tokens)
export(get_trends)
export(ids)
export(invalidate_bearer)
export(lat_lng)
export(lists_members)
Expand All @@ -49,12 +71,16 @@ export(lookup_statuses)
export(lookup_tweets)
export(lookup_users)
export(max_id)
export(media_fields)
export(metrics_fields)
export(my_friendships)
export(network_data)
export(network_graph)
export(next_cursor)
export(parse_stream)
export(place_fields)
export(plain_tweets)
export(poll_fields)
export(post_destroy)
export(post_favorite)
export(post_follow)
Expand All @@ -73,25 +99,33 @@ export(round_time)
export(rtweet_app)
export(rtweet_bot)
export(rtweet_user)
export(rules)
export(sample_stream)
export(save_as_csv)
export(search_30day)
export(search_fullarchive)
export(search_tweets)
export(search_tweets2)
export(search_users)
export(since_id)
export(stream_add_rule)
export(stream_rm_rule)
export(stream_tweets)
export(stream_tweets2)
export(trends_available)
export(ts_data)
export(ts_plot)
export(tweet_embed)
export(tweet_expansions)
export(tweet_fields)
export(tweet_shot)
export(tweet_threading)
export(tweets_data)
export(tweets_with_users)
export(unflatten)
export(user_block)
export(user_expansions)
export(user_fields)
export(user_unblock)
export(users_data)
export(users_with_tweets)
Expand Down
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# rtweet 1.1.0

- Fixed a bug that prevented posting multiple media in the same tweet.
- Argument premium is correctly handled in `search_fullarchive` and `search_30day` (#720).
- ts_plot uses the first two columns of grouped data.frames for plotting (#724 and #727).
- get_timeline returns user data for multiple accounts (#723).
- network_data now handles deleted accounts (#730).
- retryonratelimit works again on paginated endpoints (#732).
- Fixed multiple bugs that prevented `auth_sitrep()` to work in some cases.
- Provided `rbind` and subsetting methods (`[`) for rtweet new classes.
- Fixed a bug about sending a private message (#735).
- Provided a function `clean_tweets()` for cleaning entities from the text of tweets (#721).
- New helper methods for extracting data from entities in tweets: `entity()`.
- Columns of the parsed output are now always in the same order (#740).
- New methods to retrieve `ids()` from multiple classes and print nicer in `post_tweet()` (#452).
- `post_tweet()` now invisible returns the tweet information.
- Provides initial support for API v2 for streaming endpoints:
`filtered_stream()` and `sample_stream()`, including adding rules
`stream_add_rules()` and `stream_rm_rules()`.
- Deprecated old stream function.
- Handle more graciously if a whole data.frame is used for `lookup_tweets()`.

# rtweet 1.0.2

- Exported again `tweets_with_users` and `users_with_tweets` because Twitmo depends on them.
Expand Down
2 changes: 2 additions & 0 deletions R/annotations.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#'
#' @references <https://developer.twitter.com/en/docs/twitter-api/annotations/overview>
121 changes: 121 additions & 0 deletions R/api_v2_utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Creating requests ####
auth_is_bearer <- function(token = NULL) {

if (is.null(token)) {
token <- auth_get()
}
inherits(token, "rtweet_bearer")
}


# Check token readiness for API v2
#
# Check if current authentication is ready for API v2 usage.
# @param token The token to check if can be used for API v2.
# @param mechanism Which flavor of authentication must be used.
#
# The authentication method required for each endpoint might change, this is a
# helper for examples.
#
# @return If no issue is found the original token, if something is amiss it raises an error.
# @export
#
# @examples
# if (auth_has_default()) {
# tryCatch(check_token_v2())
# }
check_token_v2 <- function(token = NULL, mechanism = "bearer") {

token <- token %||% auth_get()

if (mechanism == "bearer" && !auth_is_bearer(token)) {
abort("A bearer `token` is needed for this endpoint.")
}
token
}

# General function to create the requests for Twitter API v2 with retry limits
# and error handling
req_v2 <- function(token = NULL) {

token <- check_token_v2(token)
req <- httr2::request("https://api.twitter.com/2")
req_headers <- httr2::req_headers(req,
`Content-type` = "application/json",
Authorization = paste0("Bearer ", token$token)
)
req_try <- httr2::req_retry(req_headers,
is_transient = twitter_is_transient,
after = twitter_after)
req_try
}

twitter_is_transient <- function(resp) {
httr2::resp_status(resp) %in% c(403, 503) &&
identical(httr2::resp_header(resp, "x-rate-limit-remaining"), "0")
}

twitter_after <- function(resp) {
when <- as.numeric(httr2::resp_header(resp, "x-rate-limit-reset"))
when - unclass(Sys.time())
}


endpoint_v2 <- function(token, path, throttle) {

req <- httr2::req_url_path_append(req_v2(token), path)
httr2::req_throttle(req, throttle, realm = path)
}

prepare_params <- function(x) {
lapply(x, paste, collapse = ",")
}

# Handling responses ####
parsing <- function(x) {
if (!is.logical(x) || any(is.na(x))) {
stop("parse should be either TRUE or FALSE", call. = FALSE)
}
if (length(x) > 1) {
stop("parse should be of length 1", call. = FALSE)
}
if (isTRUE(x)) {
stop("Parsing for the rtweet API v2 is not yet implemented", call. = FALSE)
}
}

l_minus <- function(l, minus) {
keep <- setdiff(names(l), minus)
l[keep]
}

# Handle the response and give attributes
resp <- function(obj, type = "json", ...) {
out <- switch(type,
"json" = httr2::resp_body_json(obj, ...),
"html" = httr2::resp_body_html(obj, ...),
"xml" = httr2::resp_body_xml(obj, ...))
class(out) <- c("Twitter_resp", class(out))

if (has_name_(out, "meta")) {
meta <- data.frame(sent = strptime(out$meta$sent, tz = "UTC",
format = "%Y-%m-%dT%H:%M:%OS"))
if (has_name_(out$meta, "summary")) {
meta <- cbind(meta, list2DF(out$meta$summary))
}
rest <- list2DF(l_minus(out$meta, c("summary", "sent")))
if (ncol(rest) >= 1 && nrow(rest) == 1) {
meta <- cbind(meta, rest)
} else if (nrow(rest) > 1) {
stop("Please check")
}
out$meta <- meta
}

if (has_name_(out, "errors")) {
out$errors <- do.call(rbind, lapply(out$errors, list2DF))
}
out
}


Loading

0 comments on commit f6ffa1a

Please sign in to comment.