Created
October 15, 2015 00:35
-
-
Save ishiy1993/cad7b78378df73d11095 to your computer and use it in GitHub Desktop.
Haskellでツイート
This file contains 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 #-} | |
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