Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #242 from cjbarrie/barrie-branch
Browse files Browse the repository at this point in the history
Update vignette; fix order of parameter documentation in build_queryv2.R
  • Loading branch information
cjbarrie authored Oct 11, 2021
2 parents 379165b + 7d822f9 commit 2dc53ff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion R/build_queryv2.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#' a character object query string to be input as query parameter to \code{\link{get_all_tweets}}.
#'
#' @param query string or character vector, search query or queries
#' @param exact_phrase If `TRUE`, only tweets will be returned matching the exact phrase
#' @param users string or character vector, user handles to collect tweets from the specified users
#' @param reply_to string or character vector, user handles to collect replies to the specified users
#' @param retweets_of string or character vector, user handles to collects retweets of tweets by the specified users
#' @param exact_phrase If `TRUE`, only tweets will be returned matching the exact phrase
#' @param exclude string or character vector, tweets containing the keyword(s) will be excluded
#'
#' @param is_retweet If `TRUE`, only retweets will be returned; if `FALSE`, retweets will be excluded; if `NULL`, both retweets and other tweet types will be returned.
Expand Down
49 changes: 33 additions & 16 deletions vignettes/academictwitteR-build.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,39 @@ tweets <-

This is the equivalent of the OR operator logics detailed by Twitter [here](https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query).

Note that the "AND" operator is implicit when specifying more than one character string in the query. Thus, when searching for all elements of a character string, a call may look like:

```{r, eval=F}
tweets <- get_all_tweets(
query = c("twitter social"),
users = c("cbarrie", "jack"),
start_tweets = "2020-01-01T00:00:00Z",
end_tweets = "2020-05-01T00:00:00Z",
n = 1000
)
```

, which will capture tweets containing *both* the words "twitter" and "social." The same logics apply for hashtag queries.

Finally, we can search for *exact* phrases by using an additional optional parameter `exact_phrase`. So, if we wanted to search tweets containing, for example, the exact phrase "Black Lives Matter," we could do the following:

```{r, eval = F}
tweets <-
get_all_tweets(
query = "Black Lives Matter",
exact_phrase = T,
start_tweets = "2021-01-04T00:00:00Z",
end_tweets = "2021-01-04T00:45:00Z",
n = Inf
)
```

## Checking your query

When building your query you can also check the query you are building separately with the `build_query()`, which is called inside the `get_all_tweets()` function.

So, the above query focusing on Seattle is querying the following, which we can build separately as so:
Expand All @@ -221,22 +254,6 @@ build_query(

Here we can see and check the format of the query sent to the Twitter API.

Note that the "AND" operator is implicit when specifying more than one character string in the query. See [here](https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query) for information on building queries for search tweets.

As such, if we wanted to search for tweets containing all the words "dog" and "cat" then we would do the following:

```{r, eval = F}
tweets <-
get_all_tweets(
query = c("dog cat"),
start_tweets = "2019-12-31T10:00:00Z",
end_tweets = "2020-01-01T10:00:00Z"
)
```


## Getting user tweets

Finally, we can combine all of the above search functionality when searching by a set of users. To do this we simply need to specify the user or set of users as follows:
Expand Down

0 comments on commit 2dc53ff

Please sign in to comment.