Skip to contents

Create a traktok query from the given parameters.


query(and = NULL, or = NULL, not = NULL)

query_and(q, field_name, operation, field_values)

query_or(q, field_name, operation, field_values)

query_not(q, field_name, operation, field_values)


and, or, not

A list of AND/OR/NOT conditions. Must contain one or multiple lists with field_name, operation, and field_values each (see example).


A traktok query created with query.


The field name to query against. One of: "create_date", "username", "region_code", "video_id", "hashtag_name", "keyword", "music_id", "effect_id", "video_length".


One of: "EQ", "IN", "GT", "GTE", "LT", "LTE".


A vector of values to search for.


A traktok query.


TikTok's query consists of rather complicated lists dividing query elements into AND, OR and NOT:

  • and: The and conditions specify that all the conditions in the list must be met

  • or: The or conditions specify that at least one of the conditions in the list must be met

  • not: The not conditions specify that none of the conditions in the list must be met

The query can be constructed by writing the list for each entry yourself, like in the first example. Alternatively, traktok provides convenience functions to build up a query using query_and, query_or, and query_not, which make building a query a little easier. You can learn more at


if (FALSE) {
# using query directly and supplying the list
query(or = list(
    field_name = "hashtag_name",
    operation = "EQ",
    field_values = "rstats"
    field_name = "keyword",
    operation = "EQ",
    field_values = list("rstats", "API")
# starting an empty query and building it up using the query_* functions
query() |>
  query_or(field_name = "hashtag_name",
           operation = "EQ",
           field_values = "rstats") |>
  query_or(field_name = "keyword",
           operation = "IN",
           field_values = c("rstats", "API"))