#' Authenticate Function
#'
#' This function allows you to authenticate with the reddit API.
#' It will open a browser window, where you will have to authorize.
#' Set up a reddit app here: https://www.reddit.com/prefs/apps
#' And set the redirect uri to: http://localhost:1410/
#' @param key Your reddit API key
#' @param secret Your reddit API secret key
#' @keywords reddit oAuth2 authenticate
#' @export
#' @examples
#' RedditAuth("YOURAPPKEY", "YOURSECRETKEY")
RedditAuth <- function(key, secret) {
# Set up httr for reddit API calls ----------------------------------------
### httr bugfix from https://github.com/r-lib/httr/pull/485
library(devtools)
devtools::install_github("r-lib/httr#485")
library(httr)
userAgent <- "screddr thread and comment scraper"
# Reddit OAuth settings from https://github.com/reddit/reddit/wiki/OAuth2
endpoint <- oauth_endpoint(
authorize = "https://www.reddit.com/api/v1/authorize",
access = "https://www.reddit.com/api/v1/access_token"
)
app <<- oauth_app("screddr", key, secret)
token <<- oauth2.0_token(
endpoint = endpoint,
app = app,
scope = c("read", "modposts"),
use_basic_auth = TRUE,
cache = F,
config_init = user_agent(userAgent)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.