DESCRIPTION

Reddit::Client provides methods and object wrappers for objects exposed . This module handles HTTP communication, oauth session management, and communication with Reddit's external API. For more information about the Reddit API, see https://github.com/reddit/reddit/wiki/API.

Beginning August 3rd, 2015, the Reddit API requires Oauth authentication. This amounts to two extra arguments at the beginning of your script; in exchange you you twice as many requests per minute as before (60 vs 30) and some added convenience on the back end.

To get Oauth keys, visit your apps page: https://www.reddit.com/prefs/apps. Choose a "script" type app. None of the other fields are needed for a script type app; you can put in 127.0.0.1 for the URLs or whatever you like.

Every account that uses this script must have permission to use it. So for example if you were to check the inboxes of your various accounts, each one would need permission. To add accounts click "add developer" on the right, after you've created the app.

Methods

1. All methods that return lists of things return them as a Perl list-- that is, a reference to an anonymous array. In practice this means that you get at the values with @$array instead of @array.

2. All methods that return lists of things accept three optional parameters: limit, before, and after. You may recognize them from your address bar when viewing pages after the front page. limit defaults to 25 with a maximum of 100. (If limit is present but false, this is interpreted as "no limit" and the maximum is returned.) before and after limit results to those posted before before and after after.

Methods

comment

comment ( $fullname, $text )

Make a comment under $fullname, which must be either a post or a comment. Return the fullname of the new comment.

Create a multireddit. The only required argument is the name. A multi can also be created with edit_multi, the only difference being that create_multi will fail with a HTTP 409 error if a multi with that name already exists.

Returns a hash of information about the newly created multireddit.

name The name of the multireddit. Maximum 50 characters. Only letters, numbers and underscores are allowed. Required.

description Description of the multi. This can contain markdown.

visibility One of 'private', 'public', or 'hidden'. Default 'private'.

subreddits or subs: An array reference.

The remaining arguments don't currently do anything. It seems like at least some of them are intended for future mobile updates.

content is the new page content. Can be empty but must be defined. Maximum 524,288 characters.

reason is the edit reason. Max 256 characters, will be truncated if longer. Optional.

previous is the ID of the intended previous version of the page; if provided, that is the version the page will be rolled back to in a rollback. However, there's no way to find out what this should be from the Reddit website, or currently from Reddit::Client either. Use it only if you know what you're doing. Optional.

1. choices is an array of hash references containing the flair options. Most important is flair_template_id, which is used to set the flair of a post or user with set_post_flair or set_user_flair. flair_text contains the text of the flair.

Returns a list of Message objects, where view is one of the MESSAGE constants. All arguments are optional. If all are omitted your default inbox will be returned-- what you would see if you went to reddit.com and clicked the mailbox icon.

Get a hash of information about a multireddit. $username defaults to your username.

If expand is true, returns more detailed information about the subreddits in the multi. This can be quite a bit of information, comparable to the amount of information contained in a Subreddit object, however it's not exactly the same, and if you try to create a Subreddit object out of it you'll fail.

get_permalink

get_permalink ( $comment_id, $post_id )

Returns a permalink for $comment_id. If you already have a Comment object, use its get_permalink function instead, ala $comment-get_permalink()>.

This version causes an extra request because it has to ask Reddit for the parent post's URL first, while a Comment object already has that information. It's provided for backwards compatibility, and for the rare case when you may have a comment's ID but not a comment object (perhaps you have a list of IDs stored in a database). It may be deprecated in the future.

Get an Oauth token from Reddit. This is analogous to the old login function, and can be considered identical, with the exception that, if your script runs continuously for more than an hour, a new token will be obtained hourly.

Get information about a user, where view is one of the USER constants: overview, comments, submitted, gilded, upvoted, downvoted, hidden, or saved. Defaults to overview, which shows the user's most recent comments and posts.

Note that if you try to get the upvoted, downvoted, hidden, or saved activity for a user other than yourself, Reddit will return a 403 error, so be sure to wrap requests in a try/catch (http://redditclient.readthedocs.org/en/latest/examples/#catch-exceptions) if there's any chance that might happen. (Of course, all requests should be wrapped in a try/catch anyway, the internet being an unpredictable place.)

The result can be a list of Links, Comments, or a mix of both, depending on what view you requested. You can determine which is which by looking at the type property, which is "t1" for comments and "t3" for posts.

has_token

has_token()

Return true if a valid Oauth token exists.

hide

hide ( $fullname )

Hide a post.

info

info ( $fullname )

Returns a hash of information about $fullname. $fullname can be any of the 8 types of thing.

Mark everything in your inbox as read. May take some time to complete.

me

me()

Return an Account object that contains information about the logged in account. Aside from static account information it contains the has_mail property, which will be true if there is anything in your inbox.

Instantiate a Reddit::Client object. Optionally get an Oauth token (analogous to logging in) at the same time. If any of the four optional arguments are used, all are required.

$user_agent is always required, and should be something descriptive that uniquely identifies your app. The API Rules (https://github.com/reddit/reddit/wiki/API#rules) say it should be "something unique and descriptive, including the target platform, a unique application identifier, a version string, and your username as contact information".

It also includes this warning: "**NEVER lie about your user-agent.** This includes spoofing popular browsers and spoofing other bots. We will ban liars with extreme prejudice."

Submit a link. Returns the fullname of the new post. If inbox_replies is defined and is false, disable inbox replies for that post. If repost is true, the link is allowed to be a repost. (Otherwise, if it is a repost, the request will fail with the error "That link has already been submitted".)

As a valued partner and proud supporter of MetaCPAN, StickerYou is
happy to offer a 10% discount on all Custom Stickers,
Business Labels, Roll Labels,
Vinyl Lettering or Custom Decals. StickerYou.com
is your one-stop shop to make your business stick.
Use code METACPAN10 at checkout to apply your discount.