Last active
December 10, 2015 11:29
-
-
Save songpp/4428212 to your computer and use it in GitHub Desktop.
Haskell版 通过rest api获取diigo收藏夹
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
| module DiigoBookmarkApi where | |
| import Codec.Binary.Base64.String | |
| import Network.HTTP.Conduit | |
| import Network.HTTP.Types.Header | |
| import Data.CaseInsensitive (mk) | |
| import Text.Printf | |
| import qualified Data.ByteString.Lazy.Char8 as L | |
| import qualified Data.ByteString.UTF8 as U | |
| username = "" | |
| password = "" | |
| apiKey = "" | |
| main :: IO () | |
| main = do | |
| req' <- parseUrl $ | |
| printf "https://secure.diigo.com/api/v2/bookmarks?key=%s&user=%s&count=10" apiKey username | |
| let req = req' { | |
| secure = True | |
| ,responseTimeout = Just 5000000 | |
| ,requestHeaders = [ | |
| basicAuthorizationHeader username password | |
| ] | |
| } | |
| -- putStrLn $ show (requestHeaders req) | |
| resp <- withManager $ httpLbs req | |
| L.putStrLn $ responseBody resp | |
| basicAuthorizationHeader :: String -> String -> Header | |
| basicAuthorizationHeader user pass = | |
| (mk $ U.fromString "Authorization", | |
| U.fromString $ "Basic " ++ encode (username ++ ":" ++ password) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment