はてなの OAuth認証をdispatch つかってアクセスしてみる
import dispatch.classic._ | |
import oauth._ | |
import OAuth._ | |
val consumer = new Consumer("9RT2jo", "wo32BVY") | |
val http = new Http | |
val u = (:/("www.hatena.com") / "oauth" ).secure | |
// token を取得 | |
val request_token = http(u / "initiate" << Map("scope" -> "read_public") <@ (consumer,"oob") as_token) | |
// verifier を取得する URLを表示、このURLにブラウザでアクセスして 値を確認する。 | |
val vrfyurl = (u / "authorize" <<? Map("oauth_token" -> request_token.value)).to_uri | |
println("Get veifier value from this url: " + vrfyurl) | |
val authverify:String = readLine("Please Input Verify Value: ") | |
println("value = " + authverify) | |
// verifier を使って access_token を取得する | |
val access_token = http(u / "token" <@ (consumer, request_token, authverify) as_token) | |
println("access_token: " + access_token.value) | |
println("access_token_secret: " + access_token.secret) | |
// 取得した access_token を使ってAPIにアクセス | |
val result = http(url("http://n.hatena.com/applications/my.json") <@ (consumer, access_token) as_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment