'Filter tweets for a given account or ID, but not having to account for tweets published from this account in R?
I would like to extract tweets with R for any determined account. Is that possible? I have tried with:
library(rtweet)
api_key <- "xxxxxxxxxxxxxxxxxxxxxxxxxx"
api_secret_key <- "xxxxxxxxxxxxxxxxxxxxxxxxxx"
access_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
access_secret ="xxxxxxxxxxxxxxxxxxxxxxxxxx"
token <- create_token(
app = "example coding",
consumer_key = api_key,
consumer_secret = api_secret_key,
access_token = access_token,
access_secret = access_secret)
search_tweets("@elonmusk", n = 10, lang ='en')
I will really appreciate any help, thank you in advance.
Solution 1:[1]
If I am understanding correctly, then you would like to only return tweets by the specific user and not mentions, etc. search_tweets will return any mentions of that user, but if you want to get that accounts actual tweets, then you can use get_timeline, which can return the n most recent tweets.
library(rtweet)
get_timeline("elonmusk", n = 5)
Output
# A tibble: 5 × 90
user_id status_id created_at screen_name
<chr> <chr> <dttm> <chr>
1 44196397 152816042… 2022-05-21 23:46:52 elonmusk
2 44196397 152815906… 2022-05-21 23:41:27 elonmusk
3 44196397 152815878… 2022-05-21 23:40:20 elonmusk
4 44196397 152815834… 2022-05-21 23:38:35 elonmusk
5 44196397 152812441… 2022-05-21 21:23:47 elonmusk
# … with 86 more variables: text <chr>,
# source <chr>, display_text_width <dbl>,
# reply_to_status_id <chr>,
# reply_to_user_id <chr>,
# reply_to_screen_name <chr>, is_quote <lgl>,
# is_retweet <lgl>, favorite_count <int>,
# retweet_count <int>, quote_count <int>, …
Then, you can do other filtering/subsetting to remove replies, etc., such as:
library(dplyr)
get_timeline("elonmusk", n = 5) %>%
filter(is.na(reply_to_status_id))
Solution 2:[2]
IIS is meant for local development. What you want to do is to publish your application. There are many hosting providers, but if we stick to Microsoft, you can use Azure to publish your application:
https://docs.microsoft.com/en-us/azure/app-service/quickstart-dotnetcore?tabs=net60&pivots=development-environment-vs
It is paid, however you can register to get temporary free access to test the solution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AndrewGB |
| Solution 2 |
