ãä½ãTwitterã使ã£ããµã¼ãã¹ãä½ã£ã¦ã¿ããã¦ãæéã空ãã¦ããæã«Twitterã®ä»æ§ãçºãã¦ãã¾ãã
Twitterã¯APIãå
å®ãã¦ãã¦ãé常ã«éçºè
ãã¬ã³ããªã¼ã§ãã
ãã APIã®ä½¿ç¨ã«ã¤ãã¦ã¯åæ°å¶éãªã©ããç¨åº¦ã®å¶ç´ãããã®ã§ãç®çã«æ²¿ã£ã¦ä½¿ãå¿
è¦ãããã¾ãã
主ãªAPIã¯ï¼ç¨®é¡ãã£ã¦ãããããã®ç¹å¾´ã¨å¶ç´ã§ãã
- REST API Methods
ãã¦ã¼ã¶ã¼ãè¡ãæä½ã«é¢ããAPIã§ãã
ä¸è¬çãªTwitterã¯ã©ã¤ã¢ã³ãã½ããã¯ãããã使ã£ã¦ä½ããã¦ãã¾ãã
IPã¨ã¢ã«ã¦ã³ããã¼ã¹ã§ã®å¶éã§ãï¼æéã«150åã¾ã§
ç³è«ããã¦è¨±å¯ãåããã°20,000åã¾ã§å¢ãããããã§ãã
- Search API Methods
ãååã®éãæ¤ç´¢ç³»ã®APIã§ãã
IPã¢ã«ã¦ã³ããã¼ã¹ã®å¶éãREST APIã«æ¯ã¹ã¦ã極ãã¦å¤ãåæ°ã使ããããã§ãã
ãããç³è«ã«ãã£ã¦åæ°ãå¢ãããããã§ãã
ãä¸è¨äºã¤ã«æ¯ã¹ã¦ç°è²ã®APIãªã®ãStreaming APIã§ããåæ°å¶ç´ããªã使ããæãç´ æµã§ãã
Searchã¨REST APIã¯ä¸åãã¨ã«æ¥ç¶åæãã¦ä½¿ãäºãåºæ¬ã§ãï¼pullåï¼
ããã«å¯¾ãã¦Streaming APIã¯ã¤ãªãã£ã±ãªãã§ãTwitterã®ãµã¼ãã¼ã®æ¹ããæ
å ±ãéã£ã¦ãã¦ããã¾ããï¼pushåï¼
æ¤ç´¢ãçµ±è¨çã§ä½¿ãã®ã«ãã¤ã¹ãªAPIã§ãã
ãStreaming APIã®ä¸ã«ã大ããäºã¤ã®ç³»çµ±ãããã¾ãã
å
¨é¨ã®timelineãæ¾ã£ã¦ãã系統ã¨ãåå¾å¯¾è±¡ã®userãçµã£ã¦ã®ç³»çµ±ã§ãã
ãfirehose, gardenhose, sample(spritzer)ã¯ãpublic_timelineã«é¢ããAPIã§ãã
firehoseã¯ãå
¨ã¦ã®public_timelineãæµãã¦ããããã§ãã2010/03/09æç¹ã§ã¯ãGoogle,Microsoft,Yahooã®ä»ã«ãã³ãã£ã¼ç³»ã®7社ã®ã¿ãæ¥ç¶è¨±å¯ãããã¦ãã¾ããã¡ãªã¿ã«Google,Microsoft,Yahooã®3社ããã®ã©ã¤ã»ã³ã¹æã¯ãæ¨å®ã§å¹´é30ååã ã¨ãã
gardenhoseã¯ãã©ã³ãã ã«ãµã³ããªã³ã°ãããçºç¾ãåå¾ã§ãã¾ãããããå©ç¨ã«ã¯è¨±å¯ãå¿
è¦ã§ãã
sample(æ§spritzer)ã¯ãgardenhoseããæ´ã«å°ãªããªã£ããµã³ããªã³ã°ã§ããï¼ããã§ãããããããæµãã¦ãã¾ããï¼
ãbirddog, shadow, filter(follow)ã¯user_timelineã«é¢ããAPIã§ãã
briddogã¯40ä¸ã¦ã¼ã¶ãshadowã¯8ä¸ã¦ã¼ã¶ãfilterã¯400ã¦ã¼ã¶ã¾ã§followã§ãã¾ãã
briddogã¨shadowã¯è¨±å¯å¶ã§ãã
Search,REST APIã®å¶éåæ°ã¯å²ã¨ããããå¤ãã£ã¦ããããã§ãã
ã¾ãTwitteræ¬ä½ã®è² è·ã«ãã£ã¦ãä¸æçã«å¶éãå¤ãããã¨ãããããã§ãã
以ä¸ããµã³ãã«ã¢ããªã§ãã
ãã°ãããã¼ãããã®Twitter Streaming APIをRubyで試してみるãã®ã¾ã¾ã§ãã
#!/usr/bin/env ruby # coding: utf-8 require 'net/http' require 'uri' require 'rubygems' require 'json' USERNAME = '_USERNAME_' # ãããæ¸ãæãã PASSWORD = '_PASSWORD_' # ãããæ¸ãæãã uri = URI.parse('http://stream.twitter.com/spritzer.json') Net::HTTP.start(uri.host, uri.port) do |http| request = Net::HTTP::Get.new(uri.request_uri) # Streaming APIã¯Basicèªè¨¼ã®ã¿ request.basic_auth(USERNAME, PASSWORD) http.request(request) do |response| raise 'Response is not chuncked' unless response.chunked? response.read_body do |chunk| # 空è¡ã¯ç¡è¦ãã = JSONå½¢å¼ã§ã®ãã¼ã¹ã«å¤±æããã次㸠status = JSON.parse(chunk) rescue next # åé¤éç¥ãªã©ã'text'ãã©ã¡ã¼ã¿ãå«ã¾ãªããã®ã¯ç¡è¦ãã¦æ¬¡ã¸ next unless status['text'] user = status['user'] puts "#{user['screen_name']}: #{status['text']}" end end end
â»Twitterã®ãµã¼ãã¼ç¶æ³ã«ãã£ã¦ãã¤ãªãããªãæãå¤ã
ããã¾ãã
ãå®éã«ä½¿ãã«ã¯ããã®è¾ºãã®å¦çã¨ããå¿
è¦ã«ãªããã¨æãã¾ãã
API Documentãèªãã§ããã¨ãStreaming APIã«æ¥ç¶ããã¢ããªã¯åå¾ããã ãã«å°å¿µããããã¨ããã¼ã¹ããã®ãè¯ãããã§ãã
ãã¼ã¹ãã¦æ ¼ç´ã¨ãã¯å¥ã¢ããªã«ããã¨ãç´å¾ã§ãã
åèï¼
Twitter API Wiki / Twitter API Documentation
Twitter API - TwitterまとめWiki
Twitter API 仕様書(勝手に日本語
Twitter Streaming APIをRubyで試してみる
Rubyから「Twitter Streaming API」を利用して日本語のつぶやきを取得するスクリプト。:青心工機:So-netブログ
é¢é£ï¼
5分で作るTwitterクライアント