fenrirããTwitterã«POSTãããããVBScript
使ç¨ã«é¢ãã¦ã¯èªå·±è²¬ä»»ã§ãé¡ããã¾ãï¼
ä½ããã£ã¦ã責任ã¨ãã¾ããã
èªåãå¿
è¦ãªæ©è½ã追å ãããæ´æ°ãã¦ãã¾ãã®ã§ããã¾ã«è¦ãã¨ã³ã¼ããå¤ãã£ã¦ããããããã¾ããã
åç´ã«èªåã欲ããããä½ã£ãã¨ããã ãã
ãã¹ã¯ã¼ããå¹³æéä¿¡ãã¦ããã®ã§ãã®è¾ºãå«ãªäººã¯çµ¶å¯¾ã«ä½¿ããªãã§ãã ããã
ã¨ããããã解決ããæ¹æ³ãã£ããæãã¦ãã ããã
ç¶ããè¦ãã§ã½ã¼ã¹ãè¦ãã¾ããã³ããã¨ããã¦ä½¿ã£ã¦ãã ããã
fenrirã£ã¦ä½ï¼ã£ã¦äººã¯ãã©ã³ã㣠fenrirããããã
Do Untilãã£ã¦ãé¨åãããµã¤ã¯ã ãªãã£ã¦æã£ã¦ããã©ã©ããã£ã¦è§£æ±ºãããããã ããã
以ä¸ã®ãã¼ã¸ãåèã«ããã¦(ã³ããããã)é ãã¾ããã
Scripting Weblog - [Twitter][WSH]Twitterã«ãã¹ããã http://blogs.wankuma.com/mutaguchi/archive/2008/07/02/146863.aspx SO NOTE ããã®ã¦ (ï¼^Ï^) - VBAã§JSONãã¡ã¤ã«ããã¼ã¹ãã http://d.hatena.ne.jp/so_blue/20090326/1238084885 Frown Wiki - fenrir Tips http://fw.ampll.org/index.php?fenrir%20%2F%20Tips#sb7f332c
â»2009/11/19 å
¬å¼RTåå¾ã»APIã®ç¶æ
åå¾ã追å
â»2009/11/21 vbsé¨åãã³ãããã¹ã§éè¤å®ç¾©ãã¦ããã®ã§ä¿®æ£
fenrirã®instant.iniã«è¿½å ããä¸èº«
;Twitterã«POSTãã /tp=%cmddir\twitterAccess.vbs POST "%A" ;TLã®åå¾ /tt=%cmddir\twitterAccess.vbs TL_VIEW ;Replyã®åå¾ /tre=%cmddir\twitterAccess.vbs REPLY_VIEW ;ReTweetã®åå¾ /trt=%cmddir\twitterAccess.vbs REPLY_TO_ME /trb=%cmddir\twitterAccess.vbs REPLY_BY_ME /tro=%cmddir\twitterAccess.vbs REPLY_OF_ME ;APIã®ç¶æ åå¾ /ta=%cmddir\twitterAccess.vbs API_LIMIT
vbsã®ä¸èº«(fenrirã®cmdãã©ã«ãã«twitterAccess.vbsã§ä½æ, ä¿åã¯SJISã§)
Option Explicit 'fenrirããã®å¼æ° Const PROC_POST = "POST" Const PROC_TLGET = "TL_VIEW" Const PROC_REPLY = "REPLY_VIEW" Const PROC_REPLY_TO_ME = "REPLY_TO_ME" Const PROC_REPLY_BY_ME = "REPLY_BY_ME" Const PROC_REPLY_OF_ME = "REPLY_OF_ME" Const PROC_API_LIMIT = "API_LIMIT" 'ã¦ã¼ã¶ã¼ID Const USER_NAME = "********" 'ãã¹ã¯ã¼ã Const PASSWORD = "********" 'POSTã®URL Const POST_URL = "http://twitter.com/statuses/update.json" 'TLåå¾ã®URL Const HOME_TL_URL = "http://twitter.com/statuses/home_timeline.json" 'menrionsã®URL Const MENTIONS_URL = "http://twitter.com/statuses/mentions.json" 'RTã®URL Const REPLY_TO_ME_URL = "http://twitter.com/statuses/retweeted_to_me.json" Const REPLY_BY_ME_URL = "http://twitter.com/statuses/retweeted_by_me.json" Const REPLY_OF_ME_URL = "http://twitter.com/statuses/retweeted_of_me.json" 'API limitã®URL Const API_LIMIT_URL = "http://twitter.com/account/rate_limit_status.json" 'Tweetã®åå¾æ°(200ãéç) Const GET_POST_COUNT = 60 Select Case WScript.Arguments(0) Case PROC_POST 'å¼æ°ã足ããªãå ´åã¯å¦çããªã If WScript.Arguments.Count > 1 Then Call Post(Trim(WScript.Arguments(1))) End If Case PROC_TLGET Call GetTimeLine(HOME_TL_URL) Case PROC_REPLY Call GetTimeLine(MENTIONS_URL) Case PROC_REPLY_TO_ME Call GetTimeLine(REPLY_TO_ME_URL) Case PROC_REPLY_BY_ME Call GetTimeLine(REPLY_BY_ME_URL) Case PROC_REPLY_OF_ME Call GetTimeLine(REPLY_OF_ME_URL) Case PROC_API_LIMIT Call GetAPILimit End Select 'Postãã Sub Post(postString) Dim oHTTP, sc, js, isLonger 'æåæ°ãã§ã㯠isLonger = True Do while isLonger = True If Len(postString) = 0 Then Exit Sub ElseIf Len(postString) > 140 then postString = InputBox("Message Length Over." & vbcrlf & "Edit for Input String" , "TwitterAccessAPI", postString) Else isLonger = False End If Loop Set oHTTP = WScript.CreateObject("Msxml2.XMLHTTP") Set sc = CreateObject("ScriptControl") sc.Language = "JScript" Set js = sc.CodeObject 'APIå¼ã³åºã oHTTP.Open "POST", POST_URL, False, USER_NAME, PASSWORD oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" oHTTP.setRequestHeader "X-Twitter-Client", "twitterAccess.vbs" oHTTP.setRequestHeader "X-Twitter-Client-Version", "1.0" oHTTP.send "status=" & js.encodeURIComponent(postString) 'åå¿ãå¾ ããªãã¨ãã®ã¾ã¾å¦çãç¶è¡ãã¦ããã»ã¹ãæ®ãããå¾ æ© Do Until oHTTP.readyState = "4" Loop '失æããã¨ãã ãã¨ã©ã¼ã表示 If oHttp.status <> "200" Then WScript.Echo "Post Error! Error Code : " & oHttp.status End If Set js = Nothing Set sc = Nothing Set oHTTP = Nothing End Sub 'TLãåå¾ãã Sub GetTimeLine(API_URL) Dim oHTTP, sc, js, strFunc, resp, respJson, dispStr Set oHTTP = WScript.CreateObject("Msxml2.XMLHTTP") Set sc = CreateObject("ScriptControl") sc.Language = "JScript" 'jsonã«ãã¼ã¹ããé¢æ°æåå strFunc = "function jsonParse(s) { return eval('(' + s + ')'); }" 'é¢æ°ã追å sc.AddCode strFunc Set js = sc.CodeObject 'APIå¼ã³åºã oHTTP.Open "GET", API_URL & "?count=" & GET_POST_COUNT, False, USER_NAME, PASSWORD oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" oHTTP.setRequestHeader "X-Twitter-Client", "twitterAccess.vbs" oHTTP.setRequestHeader "X-Twitter-Client-Version", "1.0" oHTTP.send null 'åå¿ãå¾ ããªãã¨ãã®ã¾ã¾å¦çãç¶è¡ãã¦ããã»ã¹ãæ®ãããå¾ æ© Do Until oHTTP.readyState = "4" Loop 'ã¹ãã¼ã¿ã¹ã®ç¢ºèª If oHTTP.status = 200 Then Set respJson = js.jsonParse(oHTTP.responseText) dispStr = "" For Each resp In respJson dispStr = dispStr & "[ " & resp.user.screen_name & " ] " & resp.text & vbcrlf Next Else dispStr = "Error! Error Code = " & oHTTP.status End If 'å 容ã®è¡¨ç¤º WScript.Echo dispStr Set respJson = Nothing Set resp = Nothing Set js = Nothing Set sc = Nothing Set oHTTP = Nothing End Sub 'API使ç¨åæ°ã¨ãã®åå¾ Sub GetAPILimit Dim oHTTP, sc, js, strFunc, respJson, dispStr Set oHTTP = WScript.CreateObject("Msxml2.XMLHTTP") Set sc = CreateObject("ScriptControl") sc.Language = "JScript" 'jsonã«ãã¼ã¹ããé¢æ°æåå strFunc = "function jsonParse(s) { return eval('(' + s + ')'); }" 'é¢æ°ã追å sc.AddCode strFunc Set js = sc.CodeObject 'APIå¼ã³åºã oHTTP.Open "GET", API_LIMIT_URL, False, USER_NAME, PASSWORD oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" oHTTP.setRequestHeader "X-Twitter-Client", "twitterAccess.vbs" oHTTP.setRequestHeader "X-Twitter-Client-Version", "1.0" oHTTP.send null 'åå¿ãå¾ ããªãã¨ãã®ã¾ã¾å¦çãç¶è¡ãã¦ããã»ã¹ãæ®ãããå¾ æ© Do Until oHTTP.readyState = "4" Loop 'ã¹ãã¼ã¿ã¹ã®ç¢ºèª If oHTTP.status = 200 Then Set respJson = js.jsonParse(oHTTP.responseText) dispStr = "" dispStr = dispStr & "[ remaining_hits ] = " & respJson.remaining_hits& vbcrlf dispStr = dispStr & "[ hourly_limit ] = " & respJson.hourly_limit& vbcrlf dispStr = dispStr & "[ reset_time ] = " & respJson.reset_time& vbcrlf dispStr = dispStr & "[ reset_time_in_seconds ] = " & respJson.reset_time_in_seconds& vbcrlf Else dispStr = "Error! Error Code = " & oHTTP.status End If 'å 容ã®è¡¨ç¤º WScript.Echo dispStr Set respJson = Nothing Set js = Nothing Set sc = Nothing Set oHTTP = Nothing End Sub