Created
February 22, 2021 16:23
-
-
Save apraga/a26da6095aac31c1eb5767eff033ef78 to your computer and use it in GitHub Desktop.
Reddit API in haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main (main) where | |
import Control.Monad.IO.Class | |
import Data.Aeson | |
import Network.HTTP.Req | |
import qualified Text.URI as URI | |
import Data.Maybe (fromJust) | |
main :: IO () | |
-- You can either make your monad an instance of 'MonadHttp', or use | |
-- 'runReq' in any IO-enabled monad without defining new instances. | |
main = runReq defaultHttpConfig $ do | |
uri <- URI.mkURI "https://www.reddit.com/api/v1/access_token" | |
let (url, options) = fromJust (useHttpsURI uri) | |
r <- req POST url NoReqBody jsonResponse $ | |
"grant_type" =: ("password" :: String) <> | |
"username" =: ("YOURID" :: String) <> | |
"password" =: ("YOURPASSWORD" :: String) <> | |
basicAuth "CLIENTID" "CLIENTSECRET" <> | |
header "User-Agent" "freebsd:trololol:v1.2.3 (by /u/USER)" | |
liftIO $ print (responseBody r :: Value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment