Registering Reminder Bot

In this tutorial we will create a bot that will remind a user of their post after some period of time.

Reddit API

Reddit provides an API for programs to perform the same tasks users perform on the site, such as reading posts and making comments. Reddit, like most sites that provide a feature like this, strictly enforces a set of rules for using the API.

The full list of updated API rules is hosted on Reddit's wiki page. Fortunately graw automatically enforces most of these for its users, but there is one responsibility left for us: creating a user agent.

A user agent describes the program connecting to the API, and Reddit specifies the following format for user agents:

<platform>:<app ID>:<version string (by /u/<reddit username>)>

In the platform field, use the platform on which your bot is hosted (e.g. Debian, or an Android version). For app ID, your Go program's import path is appropriate since it is globally unique. The version string is expected to be a semver number, which is always 0.1.0 initially. All together we have the following user agent:

Debian:github.com/turnage/reminderbot:v0.1.0 (by /u/roxven)

Registering

Reddit requires all programs using their API to authorize their access using OAuth, which associates the program with a Reddit account and authorizes some actions it can execute on behalf of the account. In the case of our bot, we want full control over an account and will own the account it controls, so we will use password based authentication and authorize all actions.

Log into the account you will use to run Reminder Bot and follow this tutorial on registering Reminder Bot under it. At the end you should have a panel that looks like this (credentials not real):

Take note of the "Client ID" and "Secret" fields once the bot is registered. You will need these in the next step.

Agent File

graw needs the registration information from the previous step to log in to Reddit. It has a specific format for this information; all we need to do is fill in this template:

user_agent: "<platform>:<app ID>:<version string> (by /u/<reddit username>)"
client_id: "client id (looks kind of like: sdkfbwi48rhijwsdn)"
client_secret: "client secret (looks kind of like: ldkvblwiu34y8hsldjivn)"
username: "reddit username"
password: "reddit password"

Fill this in and save the file somewhere; we'll need it later. Be sure not to check this into your repo; these credentials can access your account!

results matching ""

    No results matching ""