Created
December 15, 2009 16:12
-
-
Save mumoshu/257047 to your computer and use it in GitHub Desktop.
update status via dispatch.twitter
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
// [scala]update status via dispatch.twitter | |
/* | |
* Download | |
* http://databinder.net/dispatch/Download | |
* | |
* Getting started | |
* http://databinder.net/dispatch/Stdout_Walkthrough | |
* | |
* API Reference | |
* http://databinder.net/dispatch-doc/ | |
* docs for dispatch.{,{twitter,json,oauth}} might help | |
*/ | |
import dispatch.oauth._,dispatch._,dispatch.twitter._,dispatch.json.JsHttp._ | |
val http = new Http | |
val consumer = new Consumer(twitterからもらったconsumer keyとconsumer secret) | |
// 未承認のtokenをもらう | |
val token = Http(Auth.request_token(consumer)) | |
val authenticate_url = Auth.authenticate_url(token).to_uri.toString | |
// このURLをブラウザで開いて「許可」するとPINコードが払い出される。 | |
// これをverifierとして、Auth.access_tokenの第3引数に渡す | |
// tokenを承認してもらう => 承認済みのtokenがaccessToken | |
val accessTokenHandler = Auth.access_token(consumer,token,"7104862") | |
// access_token, user_id, user_nameが返ってくるので一つ目のaccess_tokenを抽出 | |
val accessToken = http(accessTokenHandler)._1 | |
val updateRequest = Status.update("Scalaのdispatch.twitterからぽすと #scala", consumer, accessToken) | |
http(updateRequest >>> System.out) | |
val status = "ねむい" | |
def update(s:String) = Status.update(s, consumer, accessToken) | |
val ret = http(update(status) ># { 'status ! text }) | |
ret == status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment