redditApiR
Daniel Tafmizi
Dr. Friedman
Lis 4370
redditApiR
Github: DanielDataGit/RedditApiR: redditApiRPackage
Authenticating Reddit Account:
- Create or log into account
- Ensure account is verified by going to account settings-email-verify
- Go to preferences (reddit.com)
- Create an App (personal use script for data collection needs)
Use the following script:
library(httr)
# Initialize parameters
client_id <- "Code under "personal use script" "
client_secret <- "next to secret"
user_agent <- "app name"
username <- "Account username"
password <- "Account Password"
# Get the access token
response <- POST(
"https://www.reddit.com/api/v1/access_token",
authenticate(client_id, client_secret),
body = list(
grant_type = "password",
username = username,
password = password
),
encode = "form",
user_agent(user_agent)
)
# Extract the access token
token <- content(response)$access_token
# Use the token to make authenticated requests
header <- c(
Authorization = paste("Bearer", token),
`User-Agent` = user_agent
)
Now you have defined User Agent and Headers. Allowing you to have authenticated access to the Reddit API.
Comments
Post a Comment