redditApiR

Daniel Tafmizi

Dr. Friedman

Lis 4370

redditApiR

Github: DanielDataGit/RedditApiR: redditApiRPackage

 Authenticating Reddit Account:

  1. Create or log into account
  2. Ensure account is verified by going to account settings-email-verify
  3. Go to preferences (reddit.com)
  4. 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

Popular posts from this blog

Mod 7 OOP

Description File