search_reddit: Search for items based on a query

Description Usage Arguments Details Value Examples

View source: R/reddit_functions.R

Description

Searches can be confined to one subreddit or conducted in all of reddit.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
search_reddit(
  query,
  accesstoken,
  subreddit = NULL,
  sort = "new",
  limit = 100,
  time = c("all", "hour", "day", "week", "month", "year"),
  type = c("link", "user", "sr"),
  after = NULL,
  before = NULL,
  output = c("df", "json", "all"),
  verbose = FALSE,
  retry = FALSE
)

Arguments

query

The search query. Maximum length of the query is 512 characters.

accesstoken

The accesstoken required to access the endpoint. Scope must be "read".

subreddit

The name of the subreddit in which the search should be conducted. If it is NULL, the search will be conducted in all subreddits.

sort

The order in which the search results should be ordered when accessing them. Possible values are:

  • new: Sorts search results by the time when they were created

  • hot: Sorts search results currently trending

  • relevance:

  • comments:

  • top: Most upvoted search results in a certain timeframe. Timeframe can be specified with time.

limit

The maximum number of search results to return. Must be a number between 1 and 100.

time

The timeframe in which the search results were created. Possible values are:

  • hour

  • day

  • week

  • month

  • year

  • all for search results from all time. The default value if time is not specified.

type

The type of item to return. Must be "link" for posts, "user" for "users or "sr" for subreddits. If it is NULL, it will return posts.

after

The fullname of a search result serving as anchor in the request. Search results after this post in the listing are returned.

before

The fullname of a search result serving as anchor in the request. Search results before this post in the listing are returned.

output

What the function should return. Choose json for an unparsed json object, df for a parsed object in form of a dataframe, and all for a list containg the json object, a dataframe, and the before and after anchors (if those exist for the endpoint).

verbose

A logical flag whether information about the data extraction should be printed to the console.

retry

A logical flag whether a failed api request should be retried. Requests will be tried up to three times with varying time intervals between requests.

Details

A '+' has to be put between multiple search terms in the query. Information on how to build advanced search queries can be found at this link: https://www.reddit.com/wiki/search

Value

Posts matching the search query as a dataframe, json object or a list containing both.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Not run: 
read_token <- get_token(scope = "read",
                        useragent = my_useragent,
                        username = my_username,
                        password = my_password,
                        client_id = my_client_id,
                        client_secret = my_client_secret)
                        
#Search for posts in a single subreddit
search_results_movies <- search_reddit(subreddit = "movies",
                                accesstoken = read_token,
                                query = "Keanu+Reeves",
                                sort = "relevance",
                                limit = 10,
                                time = "year")

# Search for posts in all of reddit
search_results_reddit <- search_reddit(subreddit = NULL,
                                      accesstoken = read_token,
                                      query = "Keanu+Reeves",
                                      sort = "relevance",
                                      limit = 10)

## End(Not run)

jfeldhege/redditoR documentation built on April 2, 2020, 9:42 p.m.