Reddit
This is CPPRAW’s main class, this must be the first class to be instantiated.
Parameters
std::string client_idYour client id.
std::string client_secretYour client secret.
std::string usernameYour reddit’s account username.
std::string passwordYour reddit’s account password.
std::string user_agentYour user agent.
Throws std::invalid_argument if there was an error getting the bearer token from the reddit API.
cppraw::reddit reddit("client-id", "client-secret","reddit-user", "reddit-password", "user-agent");
Both the client-id and the client-secret can be obtained in https://www.reddit.com/prefs/apps/
The user-agent is a string that tells the server what your application is. It can be anything, but it is not recommended to spoof a web browser or other application. For example, a user agent can be “CPPRAW v0.0.4 by u/Daeli_Smile”.
By default, your bearer token is saved to a macro-defined file called TOKEN_FILE, which is set to “token.txt”.
If you wish to change the file in which it is stored, you can #define TOKEN_FILE "another_file.txt"
before including CPPRAW/CPPRAW.hpp.
The token is saved with its expiration date, so that you dont have to get a new token every time your application is run.
Member functions
subreddit
This function returns a subreddit object refering to the subreddit you provided.
Parameters
std::string subredditThe name of the subreddit you wish to look for.
Returns cppraw::subreddit object.
Throws std::invalid_argument either if the subreddit is not found or if there was an error while getting the subreddit information from the reddit API.
cppraw::subreddit subreddit = reddit.subreddit("cpp");
post
This function returns a post object refering to the post you provided.
Parameters
std::string subredditThe name of the subreddit.
std::string idThe id of the post you wish to look for.
Returns cppraw::post object.
Throws std::invalid_argument either if the subreddit is not found or if there was an error getting the subreddit or post information from the reddit API.
cppraw::post post = reddit.post("cpp", "vgy0rt");
user
This function returns a cppraw::user object refering to the user you provided.
Parameters
std::string nameThe name of the user you wish to look for. Case insensitive.
Returns cppraw::user object.
Throws std::invalid_argument if there was an error getting the user’s information from the reddit API.
cppraw::user user = reddit.user("Daeli_Smile");