Skip to content

Commit

Permalink
fix bug in tt_user_liked_videos_api
Browse files Browse the repository at this point in the history
  • Loading branch information
JBGruber committed Oct 4, 2024
1 parent 854e97b commit 76fd13e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 12 additions & 3 deletions R/api_research.r
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ tt_query_request <- function(endpoint,
cursor = NULL,
search_id = NULL,
is_random = NULL,
token) {
token = NULL) {

if (is.null(token)) token <- get_token()

Expand Down Expand Up @@ -299,6 +299,7 @@ tt_user_liked_videos_api <- function(username,

res <- tt_user_request(endpoint = "liked_videos/",
username = u,
fields = fields,
cursor = the$cursor,
token = token)

Expand Down Expand Up @@ -444,10 +445,11 @@ tt_user_follow <- function(endpoint,
# used to iterate over search requests
tt_user_request <- function(endpoint,
username,
fields,
cursor,
token) {

httr2::request("https://open.tiktokapis.com/v2/research/user/") |>
req <- httr2::request("https://open.tiktokapis.com/v2/research/user/") |>
httr2::req_url_path_append(endpoint) |>
httr2::req_method("POST") |>
httr2::req_headers("Content-Type" = "application/json") |>
Expand All @@ -457,7 +459,14 @@ tt_user_request <- function(endpoint,
cursor = cursor)) |>
httr2::req_error(is_error = api_user_error_checker,
body = api_error_handler) |>
httr2::req_retry(max_tries = 5) |>
httr2::req_retry(max_tries = 5)

if (!missing(fields)) {
req <- req |>
httr2::req_url_query(fields = fields)
}

req |>
httr2::req_perform() |>
httr2::resp_body_json(bigint_as_char = TRUE)

Expand Down
15 changes: 14 additions & 1 deletion vignettes/research-api.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ If you wish to return the videos of a user, your can use the search again:
query() |>
query_and(field_name = "username",
operation = "EQ",
field_values = "statisticsglobe") |>
field_values = "statisticsglobe") |>
tt_search_api(start_date = as.Date("2023-11-01"),
end_date = as.Date("2023-11-29"))
```
Expand All @@ -154,6 +154,19 @@ tt_get_liked("jbgruber")

Note, that making likes public is an op-in feature of TikTok and almost nobody has this enabled, so it will give you a lot of warning...

What we can usually get is the information who a user follows:

```{r}
tt_user_following_api(username = "jbgruber")
```

And who they are followed by:

```{r}
tt_user_follower_api("https://www.tiktok.com/@tiktok")
```


## Obtain all Comments of a Video

There is again, not much to talk about when it comes to the comments API.
Expand Down

0 comments on commit 76fd13e

Please sign in to comment.