How I created a Reddit bot with Laravel

The boring part: research

  • Some subs had dedicated “flairs” for in-game pictures
  • Others didn’t, but a lot of the submission titles contained the word “screenshot
  • Creating a Reddit application
  • Authenticating via OAuth2 with the credentials provided by the application
  • Use the corresponding API calls to fetch the data I need

The fun part: programming and putting it all together

Figuring out the API calls

  1. Search subreddits that have a dedicated flair:
https://oauth.reddit.com/r/[SUBREDDIT]/search.json?q=flair:”[FLAIR]”&restrict_sr=1&sort=new
https://oauth.reddit.com/r/[SUBREDDIT]/search.json?q=title:[QUERY]&restrict_sr=1&sort=new
https://oauth.reddit.com/r/[SUBREDDIT]/new.json
https://oauth.reddit.com/api/submit
https://oauth.reddit.com/api/editusertext

Creating a client with Guzzle

Keeping track of cross-posts

php artisan make:model RedditCrossPost
Database snippet

A structured way to define the subreddits to scan

  • FlairQuery
  • SearchQuery
  • NewestQuery

Start cross-posting

$schedule->command('reddit:run-bot')->cron('*/15 * * * *')
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Wrapping up

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Introducing reBASE Gallery Beta

Oracle Xe On Download For Mac

Implementing Newton Raphson Method in Python

Unlimited Elements For Elementor Page Builder v1.4.96 — Addons Elementor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Robin Ingelbrecht

Robin Ingelbrecht

More from Medium

Top 10 PHP Hosting Providers in 2022

Learn PHP Cookie In Details ! — MyWebDiary |

Php — Twitter Sign-in & Register with Twitter API and the SDK twitter-api-php

Recover Ethereum private key from kestore file in PHP

Recover pirvate key from keystore