File: post-favorite.R

package info (click to toggle)
r-cran-rtweet 1.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,224 kB
  • sloc: sh: 13; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download
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
#' Favorites target status id.
#'
#' @inheritParams lookup_users
#' @param status_id Status id of target tweet.
#' @param destroy Logical indicating whether to post (add) or
#'   remove (delete) target tweet as favorite.
#' @param include_entities Logical indicating whether to
#'   include entities object in return.
#' @aliases post_favourite favorite_tweet
#' @examples
#' if (auth_has_default()) {
#'    rt <- search_tweets("#rstats", n = 1)
#'    post_favorite(rt$id_str)
#' }
#' @family post
#' @export
#' @references 
#' Create: <https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-favorites-create>
#' Destroy: <https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-favorites-destroy>
post_favorite <- function(status_id,
                          destroy = FALSE,
                          include_entities = FALSE,
                          token = NULL) {

  stopifnot(is.atomic(status_id))

  if (destroy) {
    query <- "/1.1/favorites/destroy"
  } else {
    query <- "/1.1/favorites/create"
  }

  params <- list(id = status_id)
  TWIT_post(token, query, params)
}