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

Commit

Permalink
Update vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
llrs committed Oct 12, 2023
1 parent f1d79bc commit 2bb404d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 600 deletions.
74 changes: 8 additions & 66 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ install.packages("rtweet", repos = 'https://ropensci.r-universe.dev')

## Usage

All users must be authenticated to interact with Twitter's APIs. The easiest way to authenticate is to use your personal twitter account - this will happen automatically (via a browser popup) the first time you use an rtweet function. See `auth_setup_default()` for details. Using your personal account is fine for casual use, but if you are trying to collect a lot of data it's a good idea to authentication with your own Twitter "app". See `vignette("auth", package = "rtweet")` for details.
All users must be authenticated to interact with Twitter's APIs.
See `vignette("auth", package = "rtweet")` for details.
```{r}
library(rtweet)
Expand All @@ -56,76 +57,17 @@ rtweet should be used in strict accordance with Twitter's [developer terms](htt
auth_as(rtweet:::rtweet_test())
```

## Usage

### Search tweets or users
Search for up to 1000 tweets containing #rstats, the common hashtag used to refer to the R language, excluding retweets:
```{r}
rt <- search_tweets("#rstats", n = 1000, include_rts = FALSE)
```
Twitter rate limits cap the number of search results returned to 18,000 every 15 minutes. To request more than that, set `retryonratelimit = TRUE` and rtweet will wait for rate limit
resets for you.
Search for 200 users with the #rstats in their profile:
```{r}
useRs <- search_users("#rstats", n = 200)
```
### Stream tweets
Randomly sample (approximately 1%) from the live stream of all tweets:
```{r, eval=FALSE}
random_stream <- stream_tweets("")
```
Stream all geo-located tweets from London for 60 seconds:
```{r, eval=FALSE}
stream_london <- stream_tweets(location = lookup_coords("london"), timeout = 60)
```
### Get friends and followers
Get all accounts followed by a user:
```{r}
## get user IDs of accounts followed by R Foundation
R_Foundation_fds <- get_friends("_R_Foundation")
## lookup data on those accounts
R_Foundation_fds_data <- lookup_users(R_Foundation_fds$to_id)
```
Get all accounts following a user:
```{r}
## get user IDs of accounts following R Foundation
R_Foundation_flw <- get_followers("_R_Foundation", n = 100)
R_Foundation_flw_data <- lookup_users(R_Foundation_flw$from_id)
```
If you want *all* followers, you'll need you'll need to set `n = Inf` and `retryonratelimit = TRUE` but be warned that this might take a *long* time.
Depending on if you are a paid user or not you can do more or less things.

### Get timelines
# Free

Get the most recent 100 tweets from R Foundation:
You can post (`tweet_post()`) and retrieve information about yourself (`user_self()`).

```{r}
## get most recent 100 tweets from R Foundation
tmls <- get_timeline("_R_Foundation", n = 100)
```
# Paid

### Get favorites
Get the 10 most recently favorited statuses by R Foundation:
```{r}
favs <- get_favorites("_R_Foundation", n = 10)
```
You can do all the other things: search tweets (`tweet_search_recent()`), retrieve your own bookmarks (`user_bookmarks()`), check who follows who, (`user_following()`, or `user_followers()`), ....

## Contact

Expand Down
18 changes: 5 additions & 13 deletions vignettes/auth.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rtweet's default authentication is shared by all user.
If it is just for a test, a workshop or a lecture it is fine.
But if you plan to use it more than a day you will benefit of authenticating yourself.
The **recommended authentication** mechanism is using `auth_setup_default()`.
The **authentication** mechanism is using your own app authentication.
It allows you to act on behalf of your personal Twitter account, as if you were performing actions on twitter.com.
If you want to collect a lot of data or implement a bot, you should instead use one of rtweet's two other authentication mechanisms:
Expand Down Expand Up @@ -78,7 +78,7 @@ auth_setup_default()

It will call `rtweet_user()` to use your current logged account on your default browser as the authentication used by `rtweet` and save it as "default" (See [Saving and loading](#save)).

#### Alternative authorization protocol
#### OAuth2 protocol

Some new functions require a different authentication mechanism[^1].
This functions will need you to first set up a client, which requires your client id and secret.
Expand All @@ -89,7 +89,7 @@ You can get them in your [developer dashboard](https://developer.twitter.com/en/

Choose one of the **App permissions**: Read, Read and write, or Read and write and Direct message
In **Type of App** select Native app
In **App info** set the callback URI to: http://127.0.0.1:1410/
In **App info** set the callback URI to: `http://127.0.0.1:1410/`

The callback URI is important as this is what rtweet will use to validate.

Expand Down Expand Up @@ -148,14 +148,7 @@ Again, you'll want to record this data in a secure place because you only get to
## Default
Now you have an auth object that you can provide to the `token` argument of any rtweet function:
```{r, eval = FALSE}
df <- search_tweets("#rstats", token = auth)
```

It's a good idea to do this once to check that you've entered all the app data correctly, but it'd be annoying if you had to pass this object around every single time.
Instead, you can call `auth_as()` to set this as the default for the remainder of the session:
You can call `auth_as()` to set this as the default for the remainder of the session:
```{r, eval = FALSE}
auth_as(auth)
Expand Down Expand Up @@ -188,7 +181,6 @@ You can see all the authentication options you have saved with `auth_list()`.
`auth_list()` reports all the available authentications at the default location (See `auth_save()` details).
If you use an authentication saved on a different path you can directly use it `auth_as("../authentications/rtweet.rds")`
`auth_setup_default()` saves the authentication as default.
So, after your initial setup you can start all your scripts with `auth_as("default")` to load it.
Clients work similarly, but the client will be saved with the name of the app you provided:
Expand Down Expand Up @@ -249,7 +241,7 @@ First looks up old authentications rtweet saved at your home directory (`~`, or
Then it reports the authentications found on the new location (rtweet \>= 1.0.0).
For each folder it reports apps and then users and bots authentications.
It is safe to use in public, as instead of the tokens or keys it reports a letter.
For users authentications it reports the user_id, so that you can check who is that user (`search_users("1251053384")`).
For users authentications it reports the user_id, so that you can check who is that user (`user_search("1251053384")`).
This makes it easier to see if there is a saved authentication with a name not matching the user_id.
It also warns you if there is the same key or token for multiple files, as this indicates a misunderstanding or a duplication of the authentication.
Loading

0 comments on commit 2bb404d

Please sign in to comment.