Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Commit

Permalink
Merge commit fixing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
llrs committed Nov 20, 2023
2 parents c31d0ee + 8e89e7a commit 0fa942d
Show file tree
Hide file tree
Showing 53 changed files with 514 additions and 1,273 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: rtweet
Title: Collecting Twitter Data
Version: 1.2.0.9005
Version: 1.2.1.9001
Authors@R: c(
person("Michael W.", "Kearney", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-0730-4694")),
Expand Down Expand Up @@ -51,7 +51,7 @@ Suggests:
maps (>= 3.4.0),
openssl (>= 2.0.2),
rmarkdown (>= 2.14),
spelling,
spelling (>= 2.2.1),
testthat (>= 3.1.0),
vcr (>= 0.6.0),
webshot (>= 0.5.3)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ S3method(rules,rules)
export(as_screenname)
export(as_userid)
export(auth_as)
export(auth_clean)
export(auth_get)
export(auth_has_default)
export(auth_list)
Expand Down
10 changes: 8 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# rtweet (development version)

* Fix problem with `auth_sitrep()` not correctly handling old tokens.

* Since httr2 > 0.2.3, rtweet refreshes OAuth 2.0 tokens automatically,
also if possible, replacing the file where they are saved.

# rtweet 1.2.1

* Fix `auth_sitrep()` to work well with OAuth2 tokens.

* Added new function `tweet_quoted()` to search who tweets quoting a tweet.

* New `tweet_post()` and `tweet_delete()` to post and delete tweets to work with the [free product](https://developer.twitter.com/en/portal/products/free).

* Since httr2 > 0.2.3, rtweet refreshes OAuth 2.0 tokens automatically,
also if possible, replacing the file where they are saved.
* Fix problems with changes on `is.atomic(NULL)`.

# rtweet 1.2.0

Expand Down
5 changes: 3 additions & 2 deletions R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ twitter_init_oauth1.0 <- function(endpoint, app, permission = NULL,
private_key = NULL) {
# Twitter requirements only allow numbers
# local environment for httr::oauth_callback to find the localhost IP.
# Which is also modified to http://127.0.0.1:1410/
# Which is also modified to `http://127.0.0.1:1410/`
withr::local_envvar("HTTR_SERVER" = "127.0.0.1")
httr::init_oauth1.0(
endpoint,
Expand All @@ -463,7 +463,8 @@ auth_path <- function(...) {
}

#' Some endpoints require OAuth 2.0 with specific permissions in order to work.
#' In order to work, the developer must configure the app with callback url: `http://127.0.0.1:1410`
#' In order to work, the developer must configure the app with callback url:
#' `http://127.0.0.1:1410/`
#' @param client Which client app will be used, see [rtweet_client()] for details.
#' @param scopes The permissions of the app, see [set_scopes()] for details.
#' By default it uses the client's scopes. Provided here in case you want to modify them.
Expand Down
42 changes: 42 additions & 0 deletions R/auth_clean.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' Remove tokens
#'
#' If there is a file with saved tokens it will delete it.
#'
#' This functions helps to comply with CRAN policy to remove files created by
#' the package.
#' @param old A logical value if you want to remove old tokens.
#' @param new A logical value if you want to remove new tokens.
#'
#' @return An invisible logical value showing the success of the operation.
#' If no tokens need to be deleted it will return FALSE too.
#' `NULL` if there is nothing to do.
#' @export
#' @examples
#' auth_clean(FALSE, FALSE)
auth_clean <- function(old = TRUE, new = FALSE) {
stopifnot(is_logical(old))
stopifnot(is_logical(new))

if (isFALSE(old) && isFALSE(new)) {
inform(c("Nothing to do",
i = "Did you meant to set `old = TRUE`?"))
return(invisible(NULL))
}
old_tokens <- find_old_tokens()
tools_tokens <- find_tools_tokens()
all_tokens_files <- c(old_tokens, tools_tokens)
if (is.null(all_tokens_files)) {
inform("No tokens were found! Nothing to do.")
return(invisible(NULL))
}
ot <- FALSE
nt <- FALSE
if (length(old_tokens) != 0 && old) {
ot <- unlink(old_tokens)
}
if (length(tools_tokens) != 0 && new) {
nt <- unlink(tools_tokens)
}
out <- old && ot || new && nt
invisible(out)
}
21 changes: 16 additions & 5 deletions R/auth_sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ auth_sitrep <- function() {
old_tokens <- find_old_tokens()
tools_tokens <- find_tools_tokens()
all_tokens_files <- c(old_tokens, tools_tokens)
# FIXME: Deal with Oauth2 tokens
if (is.null(all_tokens_files)) {
inform("No tokens were found! See ?auth_as for more details.")
return(NULL)
Expand Down Expand Up @@ -88,7 +87,12 @@ token_auth <- function(tokens) {
key = character(n))
df <- as.data.frame(t(list2DF(tokens)))
rownames(df) <- names(tokens)
colnames(df) <- c("app", "user_id", "key")
if (ncol(df) < 3L) {
x <- seq_len(ncol(df))
} else {
x <- 1L:3L
}
colnames(df) <- c("app", "user_id", "key")[x]
uk <- unique(df$key)
length_levels <- length(uk) - sum(any(uk == ""))
df$key <- factor(df$key, labels = LETTERS[seq_len(length_levels)], exclude = "")
Expand All @@ -97,8 +101,16 @@ token_auth <- function(tokens) {

#' @importFrom methods is
type_auth <- function(tokens) {
class_tokens <- vapply(tokens, is, character(1L))
class_tokens <- ifelse(endsWith(class_tokens, "Token1.0"), "token", "bearer")

class_tokens <- vapply(tokens, function(x){is(x)[1]}, character(1L))
class_tokens2 <- character(length(class_tokens))
class_tokens2[class_tokens %in% c("Token1.0", "TwitterToken1.0")] <- "token"
class_tokens2[class_tokens == "rtweet_bearer"] <- "bearer"
class_tokens2[class_tokens == "httr2_token"] <- "httr2_token"
if (any(!nzchar(class_tokens2))) {
warn("Detected some file which doesn't seems created by rtweet.", parent = current_call())
}
class_tokens2
}

move_tokens <- function(tokens, folder) {
Expand Down Expand Up @@ -179,7 +191,6 @@ handle_token <- function(tokens) {
action_tokens
}


auth_check <- function(tokens) {
type_auth <- type_auth(tokens)

Expand Down
4 changes: 2 additions & 2 deletions R/client.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ no_client <- function(call = caller_env()) {
#' @param scopes Default scopes allowed for users using this client.
#' Leave `NULL` to allow everything or choose yours with `set_scopes()`.
#' @param app Name of the client, it helps if you make it match with the name of your app.
#' On the Twitter app the Callback URI must be "http://127.0.0.1:1410/" (the trailing / must be
#' included).
#' On the Twitter app the Callback URI must be `http://127.0.0.1:1410/`
#' (the trailing / must be included).
#' @seealso scopes
#' @export
#' @examples
Expand Down
1 change: 1 addition & 0 deletions R/coords.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ lookup_coords <- function(address, components = NULL, apikey = NULL, ...) {
if (missing(address)) stop("must supply address", call. = FALSE)
stopifnot(is.atomic(address) && !is.null(address),
is.atomic(components))
stopifnot(is.atomic(address), is.atomic(components))
place <- address
if (grepl("^us$|^usa$|^united states$|^u\\.s",
address, ignore.case = TRUE)) {
Expand Down
4 changes: 2 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Defunct: Emojis codes and descriptions data.
#'
#' This data comes from "Unicode.org",
#' <http://unicode.org/emoji/charts/full-emoji-list.html>. The data are
#' <https://unicode.org/emoji/charts/full-emoji-list.html>. The data are
#' codes and descriptions of Emojis.
#'
#' @docType data
Expand All @@ -12,7 +12,7 @@ NULL
#' Defunct: Language codes recognized by Twitter data.
#'
#' This data comes from the Library of Congress,
#' <http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt>. The data are
#' <https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt>. The data are
#' descriptions and codes associated with internationally recognized languages.
#' Variables include translations for each language represented as
#' bibliographic, terminological, alpha, English, and French.
Expand Down
1 change: 1 addition & 0 deletions R/direct_messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' about the sender and recipient.
#'
#' @inheritParams TWIT_paginate_cursor
#' @inheritParams stream
#' @param next_cursor `r lifecycle::badge("deprecated")` Use `cursor` instead.
#' @return A list with one element for each page of results.
#' @examples
Expand Down
9 changes: 5 additions & 4 deletions R/favorites.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#'
#' @inheritParams TWIT_paginate_max_id
#' @inheritParams get_timeline
#' @inheritParams stream
#' @return A tibble with one row for each tweet.
#' @examples
#' if (auth_has_default()) {
#' # get likes for a single user
#' kfc <- get_favorites("KFC")
#' kfc
#' # get newer likes since last request
#' # get newer likes since last request
#' newer <- get_favorites("KFC", since_id = kfc)
#'
#' # get likes from multiple users
Expand All @@ -28,7 +29,7 @@ get_favorites <- function(user,
retryonratelimit = NULL,
verbose = TRUE,
token = NULL) {
rt <- lapply(user, get_favorites_user,
rt <- lapply(user, get_favorites_user,
n = n,
since_id = since_id,
max_id = max_id,
Expand All @@ -51,7 +52,7 @@ get_favorites_user <- function(user, ..., parse = TRUE, token = NULL) {
tweet_mode = "extended"
)
params[[user_type(user)]] <- user

results <- TWIT_paginate_max_id(token, "/1.1/favorites/list", params,
page_size = 200,
...
Expand All @@ -62,6 +63,6 @@ get_favorites_user <- function(user, ..., parse = TRUE, token = NULL) {
results$created_at <- format_date(results$created_at)
results$favorited_by <- rep(user, nrow(results))
}

results
}
1 change: 1 addition & 0 deletions R/followers.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#'
#' @inheritParams TWIT_paginate_cursor
#' @inheritParams get_timeline
#' @inheritParams stream
#' @param page `r lifecycle::badge("deprecated")` Please use `cursor` instead.
#' @references <https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids>
#' @examples
Expand Down
2 changes: 2 additions & 0 deletions R/friends.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#'
#' @inheritParams TWIT_paginate_cursor
#' @inheritParams get_followers
#' @inheritParams stream
#' @param users Screen name or user ID of target user from which the
#' user IDs of friends (accounts followed BY target user) will be
#' retrieved.
Expand Down Expand Up @@ -114,6 +115,7 @@ my_friendships <- function(user,
#' Gets information on friendship between two Twitter users.
#'
#' @inheritParams lookup_users
#' @inheritParams stream
#' @param source Screen name or user id of source user.
#' @param target Screen name or user id of target user.
#' @family friends
Expand Down
35 changes: 16 additions & 19 deletions R/http.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
TWIT_get <- function(token, api, params = NULL, ..., host = "api.twitter.com") {
resp <- TWIT_method("GET",
token = token,
api = api,
params = params,
...,
host = host
token = token,
api = api,
params = params,
...,
host = host
)

from_js(resp)
}

TWIT_post <- function(token, api, params = NULL, body = NULL, ..., host = "api.twitter.com") {
TWIT_method("POST",
token = token,
api = api,
params = params,
body = body,
...,
host = host
token = token,
api = api,
params = params,
body = body,
...,
host = host
)
}

Expand Down Expand Up @@ -95,9 +95,6 @@ TWIT_method <- function(method, token, api,
#' If you expect a query to take hours or days to perform, you should not
#' rely solely on `retryonratelimit` because it does not handle other common
#' failure modes like temporarily losing your internet connection.
#' @param parse If `TRUE`, the default, returns a tidy data frame. Use `FALSE`
#' to return the "raw" list corresponding to the JSON returned from the
#' Twitter API.
#' @param verbose Show progress bars and other messages indicating current
#' progress?
#' @returns A list with the json output of the API.
Expand Down Expand Up @@ -147,8 +144,8 @@ TWIT_paginate_max_id <- function(token, api, params,
)
if (is_rate_limit(json)) {
warn_early_term(json,
hint = paste0("Set `max_id = '", max_id, "' to continue."),
hint_if = !is.null(max_id)
hint = paste0("Set `max_id = '", max_id, "' to continue."),
hint_if = !is.null(max_id)
)
break
}
Expand Down Expand Up @@ -529,9 +526,9 @@ warn_early_term <- function(cnd, hint, hint_if) {

check_status <- function(x, api) {
switch(resp_type(x),
ok = NULL,
rate_limit = ,
error = handle_error(x)
ok = NULL,
rate_limit = ,
error = handle_error(x)
)
}

Expand Down
1 change: 1 addition & 0 deletions R/lists_members.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' owner_user parameters.
#' @param owner_user optional The screen name or user ID of the user
#' @param ... Other arguments used as parameters in query composition.
#' @inheritParams stream
#' @examples
#' if (auth_has_default()) {
#'
Expand Down
8 changes: 7 additions & 1 deletion R/lists_parsing.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ as_lists_users <- function(x) {
structure(x, class = "lists_users")
}

as.data.frame.lists_users <- function(x) {
as.data.frame.lists_users <- function(x, row.names, optional, ...) {
if (!missing(row.names)) {
warning("`row.names` argument is ignored.")
}
if (!missing(optional)) {
warning("`optional` argument is ignored.")
}
if (has_name_(x, "lists")) {
x <- x[["lists"]]
}
Expand Down
5 changes: 3 additions & 2 deletions R/lists_statuses.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
#' retweeted tweets is identical to the representation you see in
#' home_timeline.
#' @inheritParams TWIT_paginate_max_id
#' @inheritParams stream
#' @family lists
#' @family tweets
#' @return data
#' @examples
#' @examples
#' if (auth_has_default()) {
#' (rladies <- lists_statuses(list_id = "839186302968848384"))
#' (rladies <- lists_statuses(slug = "rladies1", owner_user = "RLadiesGlobal"))
Expand Down Expand Up @@ -51,7 +52,7 @@ lists_statuses <- function(list_id = NULL,
retryonratelimit = retryonratelimit,
verbose = verbose
)

if (parse) {
results <- tweets_with_users(results)
results$created_at <- format_date(results$created_at)
Expand Down
Loading

0 comments on commit 0fa942d

Please sign in to comment.