Skip to content

Instantly share code, notes, and snippets.

@ishiy1993
Created October 15, 2015 00:35
Show Gist options
  • Save ishiy1993/cad7b78378df73d11095 to your computer and use it in GitHub Desktop.
Save ishiy1993/cad7b78378df73d11095 to your computer and use it in GitHub Desktop.
Haskellでツイート
{-# LANGUAGE OverloadedStrings #-}
import Web.Authenticate.OAuth
import Data.ByteString (ByteString)
import Data.Text.Encoding (encodeUtf8)
import Network.HTTP.Conduit
myOAuth :: OAuth
myOAuth = newOAuth { oauthServerName = "api.twitter.com"
, oauthConsumerKey = "Your Consumer Key"
, oauthConsumerSecret = "Your Consumer Secret"
}
myCred :: Credential
myCred = newCredential "Your Access Token" "Your Access Token Secret"
tweet :: ByteString -> IO ()
tweet tw = do
req <- parseUrl "https://api.twitter.com/1.1/statuses/update.json"
let postReq = urlEncodedBody [("status", tw)] req
m <- newManager tlsManagerSettings
res <- do
signedreq <- signOAuth myOAuth myCred postReq
httpLbs signedreq m
return ()
main :: IO ()
main = tweet $ encodeUtf8 "Haskellでツイート"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment