Skip to content

Instantly share code, notes, and snippets.

@zaneli
Created May 19, 2013 11:31
Show Gist options
  • Save zaneli/5607412 to your computer and use it in GitHub Desktop.
Save zaneli/5607412 to your computer and use it in GitHub Desktop.
「Facebook C# SDK を F# から実行する」ブログ用
namespace Zaneli
module Facebook =
open Facebook
open System.Collections.Generic
let private appId = "393996153967424"
let private redirectUri = "http://www.zaneli.com/"
let private client = FacebookClient()
// getProfile の返り値に使用
type Profile = {Id:int; Name:string; FirstName:string; LastName:string}
// アプリ認証のためのcodeを取得するURLを生成
let getLoginUrl =
let param = dict[("app_id", box appId); ("redirect_uri", box redirectUri); ("scope", box "status_update,publish_stream")]
client.GetLoginUrl(param).AbsoluteUri
// アクセストークンを取得
let getAccessToken (code:string) =
let apiKey = "67cbe25604995a162c6a9a4c09d41545"
let param = dict[("client_id", box appId); ("client_secret", box apiKey); ("redirect_uri", box redirectUri); ("code", box code)]
let result = client.Get("oauth/access_token", param) :?> IDictionary<string, obj>
result.["access_token"] :?> string
// 自分のプロフィールを取得
let getProfile (token:string) =
let param = new Dictionary<string, obj>()
param.["access_token"] <- token
let result = client.Get("me", param) :?> IDictionary<string, obj>
{Id = int (result.["id"] :?> string); Name = result.["name"] :?> string; FirstName = result.["first_name"] :?> string; LastName = result.["last_name"] :?> string}
// 投稿
let post (token:string) (message:string) =
let param = new Dictionary<string, obj>()
param.["access_token"] <- token
param.["message"] <- message
let result = client.Post("me/feed", param) :?> IDictionary<string, obj>
result.["id"] :?> string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment