Giter VIP home page Giter VIP logo

fb's Introduction

fb

Build Status

Haskell bindings to Facebook's API

Example code to get User Access token

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

import Facebook
import Network.HTTP.Client
import Network.HTTP.Client.TLS
import Control.Monad.Trans.Control
import Control.Monad.Trans.Resource
import Control.Monad.IO.Class
import Data.Monoid ((<>))
import Data.ByteString.Char8 (pack)
import Data.Text hiding (pack)
import Data.Aeson
import qualified Data.Text.Encoding as TE

myCreds :: Credentials
myCreds =
  Credentials
  { appName = "Your_APP_Name"
  , appId = "your_app_id"
  , appSecret = "xxxxxxxxxxxxxxxxx"
  }

main :: IO ()
main = do
  mgr <- newManager tlsManagerSettings
  let redirectUrl = "https://www.yourdomain.com/"
  runResourceT $
    runFacebookT myCreds mgr $
    do url1 <- getUserAccessTokenStep1 redirectUrl ["public_profile", "email"]
       liftIO $ print ("Paste the url in browser and get code: " <> url1)
       code <- liftIO $ getLine
       token <- getUserAccessTokenStep2 redirectUrl [("code", pack code)]
       liftIO $ print token

Snippet to get your Profile Picture:

       (picture :: Value) <-
         getObject "/me/picture" [("redirect", "0")] (Just token)
       liftIO $ print picture

Snippet to get your firstname, lastname:

       user <- getUser "me" [("fields", "first_name,last_name")] (Just token)
       liftIO $ print user

fb's People

Contributors

meteficha avatar psibi avatar whittle avatar paulrzcz avatar stepcut avatar gabrielprioli avatar ddssff avatar snoyberg avatar alanpog avatar tolysz avatar timp avatar

Watchers

Sarthak Bagaria avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.