SlideShare a Scribd company logo
1 of 22
Download to read offline
BigDataの集め方
              RubyでTwitter Streaming APIを使ってみた


                           @Mahito




12年7月30日月曜日
自己紹介
      {
              名前 : まひと
              ID   : @Mahito
              仕事 : [仮想化, NoSQL, BigData]
              コミュニティ : [Ruby, MongoDB]
              趣味 : [釣り, 熱帯魚, 温泉, 勉強会]
      }
12年7月30日月曜日
本日のお話


              簡単なBigDataの集め方と
              して、Twitterからのデー
              タ収集方法と利用サンプル
              のご紹介


12年7月30日月曜日
BigData時代到来!

          富、名声、力、この世のすべてを手に入れた
          男、海賊王ゴールド・D・ロジャー。彼の死に際
          に放った一言は、人々をデータの海へ駆り立て
          た。
         「オレの利益か?欲しけりゃくれてやる。探せ!
         この世のすべてをそこへ置いてきた!!」
         男たちは会社の利益を目指し、様々なデータを追
         い続ける。

         世はまさに、BigData時代!!

12年7月30日月曜日
            |i
                   \      |.|
                             長いので一言で
                    ト\   /| ト
                    | トヽ   / | | ト
                    | | トヽ\/| | | ト    /
                    | | | ト\≧三ミゞ=イ/
                   ム彡''´ ̄ ̄    ̄ ヽ{__..
                  /             V´
                  ノ  __          ',
               ,. == y ̄, __、\_        )
               |i  }-| ゝ二 |/ ̄ ̄  /ニ,l
               ヽ__ノ/ヾ _ ノ       > }}
                                              世界的ですもんね
                / >≦'__        し /
                 Vて二オカ       (_,/}
                 Yこ二ノ!!|          }
                                              乗るしかない
                  Y͡ 从        ∠)
                  从从从トミ   _.ィニ二 ̄丶
                   ミ三三彡 ' ´      \ \
                                              このビッグデータに
                      /           \ヽ
                    /            ミ;,. ', ',
                     |   _  _ __    \',.',
                    ノ!   | V7\ ´/
                   / l /_ゝ| ト >__/ /
                   |   ヽン ´  ヽー'
                  i|                l
                  |:! ヽ              |
12年7月30日月曜日
                  | ト、 `ミ,            l
そもそもBigDataって?

              BigData自体の定義は曖昧
               データの大きさ
               データの種類
               データ構造が半構造や非構造
              ソーシャルサービスのデータやそれらの複数
              の組み合わせが例にあげられる



12年7月30日月曜日
どうやって集めるの?



              そこでTwitterですよ!



12年7月30日月曜日
ご存知とは思いますが




                 Twitter

12年7月30日月曜日
Twitter

               5億ユーザ(アクティブユーザは1.4億)
               1日あたり4.9億 tweet(日本5970万 tweet)
               1秒辺り7000 tweet(日本1400 tweet)


              余談
              2011年12月9日に放送された「天空の城ラピュ
              タ」の「バルス」の瞬間に25088 tweet/sで当時
              の最高記録を樹立

12年7月30日月曜日
先週の状況

              サマーウォーズ




12年7月30日月曜日
REST APIでデータ収集
              Twitterにはデータ取得用のREST APIが存在
              Requestに応じてJSON形式でデータ取得可能
              それらをWrappingしたライブラリも存在
               Twitter4J(Java)
               Twitter(Ruby)
               Twitter4R(Ruby)
              TwitterクライアントのほとんどはREST APIで
              実装されている(模様)

12年7月30日月曜日
REST APIでデータ収集?


               REST APIでデータ収集できないことはない
               ただし制限として350 request / hour
               Public Time Lineの情報は20 tweet/request
               さらに60秒間キャッシュが効いているため、
               1200 tweet / hourが限界




12年7月30日月曜日
そこでStreaming APIですよ

              APIを利用するとTwitter側からデータが自動
              的に送られてくる(Push式)
              APIの使用制限がない
              Streaming APIの種類は3つ
               Public Stream(Public Time Line)
               User Stream(特定のユーザ対象)
               Site Stream(Webサイト向け)


12年7月30日月曜日
Public Stream

              Public Streamにも3つの種類が存在
               filter(フィルタリングしたPublic TL)
               sample(Public TLの一部)
               firehose(一部企業向け)




12年7月30日月曜日
ブラウザでお試し

              以下のURLにアクセス
               https://stream.twitter.com/1/statuses/sample.json

              自分のTwitterIDとパスワードを入力
              (Basic認証)
              DLが開始される
              (終わらないので満足したら止めること!)



12年7月30日月曜日
Rubyでお試し
              OAuthの設定
               Twitter Developersのサイトで実施
                 https://dev.twitter.com/
                 サインイン
                 My Application
                 Create a new Application
                 入力フォームを埋めて各種Keyを入手


12年7月30日月曜日
Rubyでお試し


              Rubyのライブラリ”TweetStream”を利用
               https://github.com/intridea/tweetstream/

              “gem install tweetstream”でインストール
              TweetStreamのサンプルにそってコーディング




12年7月30日月曜日
サンプルコード(sample)
          1   require 'tweetstream'
          2   require 'yaml'
          3
          4   CONF = YAML::load(open("conf.yaml"))
          5
          6   TweetStream.configure do |config|
          7     config.consumer_key       = CONF["consumer_key"]
          8     config.consumer_secret    = CONF["consumer_secret"]
          9     config.oauth_token        = CONF["token"]
         10     config.oauth_token_secret = CONF["token_secret"]
         11     config.auth_method        = :oauth
         12   end
         13
         14   TweetStream::Client.new.sample do |status|
         15     puts status.text
         16   end



12年7月30日月曜日
サンプルコード(filter)
          1   require 'tweetstream'
          2   require 'yaml'
          3
          4   CONF = YAML::load(open("conf.yaml"))
          5
          6   TweetStream.configure do |config|
          7     config.consumer_key       = CONF["consumer_key"]
          8     config.consumer_secret    = CONF["consumer_secret"]
          9     config.oauth_token        = CONF["token"]
         10     config.oauth_token_secret = CONF["token_secret"]
         11     config.auth_method        = :oauth
         12   end
         13
         14   TweetStream::Client.new.track('Ruby') do |status|
         15     puts status.text
         16   end



12年7月30日月曜日
取得データ(1件)
              {"in_reply_to_user_id_str"=>"455267413", "place"=>nil, "text"=>"@AsantiWheels keep a look out for "Ruby"
              @SEMASHOW this year http:/     /t.co/mDUGAJlR", "contributors"=>nil, "in_reply_to_user_id"=>455267413,
              "id_str"=>"227440608116097024", "coordinates"=>nil, "geo"=>nil, "favorited"=>false, "source"=>"<a href="http:/  /
              twitter.com/download/android" rel="nofollow">Twitter for Android</a>", "possibly_sensitive_editable"=>true,
              "created_at"=>"Mon Jul 23 16:30:42 +0000 2012", "in_reply_to_screen_name"=>"AsantiWheels",
              "in_reply_to_status_id"=>nil, "possibly_sensitive"=>false, "in_reply_to_status_id_str"=>nil, "user"=>{"is_translator"=>false,
              "notifications"=>nil, "profile_use_background_image"=>true, "profile_background_image_url_https"=>"https:/       /
              si0.twimg.com/images/themes/theme1/bg.png", "time_zone"=>nil, "profile_text_color"=>"333333",
              "profile_image_url_https"=>"https:/   /si0.twimg.com/profile_images/2386225418/549WvyXy_normal", "following"=>nil,
              "verified"=>false, "profile_background_image_url"=>"http:/    /a0.twimg.com/images/themes/theme1/bg.png",
              "default_profile_image"=>false, "profile_link_color"=>"0084B4", "description"=>"car crazy Arizona guy, dodge parts monkey,
              Severed Ties O.G. member, owner of Chain Reaction ", "id_str"=>"576656522", "contributors_enabled"=>false,
              "geo_enabled"=>false, "favourites_count"=>0, "followers_count"=>26, "profile_image_url"=>"http:/    /a0.twimg.com/
              profile_images/2386225418/549WvyXy_normal", "follow_request_sent"=>nil, "created_at"=>"Thu May 10 23:21:38 +0000
              2012", "profile_background_color"=>"C0DEED", "profile_background_tile"=>false, "friends_count"=>184, "url"=>nil,
              "show_all_inline_media"=>false, "statuses_count"=>99, "profile_sidebar_fill_color"=>"DDEEF6", "protected"=>false,
              "screen_name"=>"Severed_Joe", "listed_count"=>0, "name"=>"J.M.", "profile_sidebar_border_color"=>"C0DEED",
              "location"=>"Phx, AZ", "id"=>576656522, "default_profile"=>true, "lang"=>"en", "utc_offset"=>nil}, "retweet_count"=>0,
              "id"=>227440608116097024, "entities"=>{"user_mentions"=>[{"indices"=>[0, 13], "id_str"=>"455267413",
              "screen_name"=>"AsantiWheels", "name"=>"Asanti Wheels", "id"=>455267413}, {"indices"=>[41, 50], "id_str"=>"21902226",
              "screen_name"=>"SEMASHOW", "name"=>"SEMA Show", "id"=>21902226}], "media"=>[{"type"=>"photo", "indices"=>[61, 81],
              "display_url"=>"pic.twitter.com/mDUGAJlR", "media_url_https"=>"https:/   /p.twimg.com/AygIBy6CQAA2O3i.jpg",
              "id_str"=>"227440608120291328", "sizes"=>{"small"=>{"resize"=>"fit", "h"=>680, "w"=>284}, "medium"=>{"resize"=>"fit",
              "h"=>1172, "w"=>490}, "large"=>{"resize"=>"fit", "h"=>1172, "w"=>490}, "thumb"=>{"resize"=>"crop", "h"=>150, "w"=>150}},
              "url"=>"http://t.co/mDUGAJlR", "expanded_url"=>"http:/   /twitter.com/Severed_Joe/status/227440608116097024/photo/1",
              "media_url"=>"http:/  /p.twimg.com/AygIBy6CQAA2O3i.jpg", "id"=>227440608120291328}], "hashtags"=>[], "urls"=>[]},
              "retweeted"=>false, "truncated"=>false}




12年7月30日月曜日
まとめ

              Twitter Streaming APIは簡単に利用できる
              Twitter Streaming APIを利用することで、だ
              れでも簡単にBigDataを入手することができる
               BigDataで勝ち残るポイントは
                 データを蓄積すること
                 蓄積したデータを活かすかこと



12年7月30日月曜日
完
12年7月30日月曜日

More Related Content

Similar to BigDataの集め方

データマイニング+WEB勉強会資料第6回
データマイニング+WEB勉強会資料第6回データマイニング+WEB勉強会資料第6回
データマイニング+WEB勉強会資料第6回
Naoyuki Yamada
 
Iliad or Seaside
Iliad or SeasideIliad or Seaside
Iliad or Seaside
Sho Yoshida
 
Html5 Web Applications
Html5  Web ApplicationsHtml5  Web Applications
Html5 Web Applications
totty jp
 
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
Jumpei Ogawa
 
Mixiアプリで体験する Open Social
Mixiアプリで体験する Open SocialMixiアプリで体験する Open Social
Mixiアプリで体験する Open Social
ngi group.
 
オンラインゲームソリューション@トレジャーデータ
オンラインゲームソリューション@トレジャーデータオンラインゲームソリューション@トレジャーデータ
オンラインゲームソリューション@トレジャーデータ
Takahiro Inoue
 

Similar to BigDataの集め方 (20)

クラウドではじめるリアルタイムデータ分析 #seccamp
クラウドではじめるリアルタイムデータ分析 #seccampクラウドではじめるリアルタイムデータ分析 #seccamp
クラウドではじめるリアルタイムデータ分析 #seccamp
 
Treasure data demo.0517
Treasure data demo.0517Treasure data demo.0517
Treasure data demo.0517
 
W3C Web of Thing Interest Group 最新状況
W3C Web of Thing Interest Group 最新状況W3C Web of Thing Interest Group 最新状況
W3C Web of Thing Interest Group 最新状況
 
Data apiで実現 進化するwebの世界
Data apiで実現 進化するwebの世界Data apiで実現 進化するwebの世界
Data apiで実現 進化するwebの世界
 
初めての Data api cms どうでしょう - 大阪夏の陣
初めての Data api   cms どうでしょう - 大阪夏の陣初めての Data api   cms どうでしょう - 大阪夏の陣
初めての Data api cms どうでしょう - 大阪夏の陣
 
【Techbuzz】titanium資料
【Techbuzz】titanium資料【Techbuzz】titanium資料
【Techbuzz】titanium資料
 
5分程度で分かる? Appceleratorの方のAlloy
5分程度で分かる? Appceleratorの方のAlloy5分程度で分かる? Appceleratorの方のAlloy
5分程度で分かる? Appceleratorの方のAlloy
 
How Smalltalker Works
How Smalltalker WorksHow Smalltalker Works
How Smalltalker Works
 
IPメッセージングはこうやって実装するのだ!
IPメッセージングはこうやって実装するのだ!IPメッセージングはこうやって実装するのだ!
IPメッセージングはこうやって実装するのだ!
 
データマイニング+WEB勉強会資料第6回
データマイニング+WEB勉強会資料第6回データマイニング+WEB勉強会資料第6回
データマイニング+WEB勉強会資料第6回
 
Iliad or Seaside
Iliad or SeasideIliad or Seaside
Iliad or Seaside
 
Mashup Caravan in オープンソースカンファレンス2011 Hiroshima: infoScoop OpenSource
Mashup Caravan in オープンソースカンファレンス2011 Hiroshima: infoScoop OpenSourceMashup Caravan in オープンソースカンファレンス2011 Hiroshima: infoScoop OpenSource
Mashup Caravan in オープンソースカンファレンス2011 Hiroshima: infoScoop OpenSource
 
モテる! Node.js でつくる twitter ボット制作
モテる! Node.js でつくる twitter ボット制作モテる! Node.js でつくる twitter ボット制作
モテる! Node.js でつくる twitter ボット制作
 
Html5 Web Applications
Html5  Web ApplicationsHtml5  Web Applications
Html5 Web Applications
 
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
 
Mixiアプリで体験する Open Social
Mixiアプリで体験する Open SocialMixiアプリで体験する Open Social
Mixiアプリで体験する Open Social
 
ID連携のあるとき~、ないとき~ #エンプラ編
ID連携のあるとき~、ないとき~ #エンプラ編ID連携のあるとき~、ないとき~ #エンプラ編
ID連携のあるとき~、ないとき~ #エンプラ編
 
知っ徳! 納徳!Magic Leap 《アプリ開発~Web開発の超基礎編》
知っ徳! 納徳!Magic Leap 《アプリ開発~Web開発の超基礎編》知っ徳! 納徳!Magic Leap 《アプリ開発~Web開発の超基礎編》
知っ徳! 納徳!Magic Leap 《アプリ開発~Web開発の超基礎編》
 
オンラインゲームソリューション@トレジャーデータ
オンラインゲームソリューション@トレジャーデータオンラインゲームソリューション@トレジャーデータ
オンラインゲームソリューション@トレジャーデータ
 
Apache Drill で見る Twitter の世界
Apache Drill で見る Twitter の世界Apache Drill で見る Twitter の世界
Apache Drill で見る Twitter の世界
 

More from Mahito Ogura (6)

ChefユーザのためのAnsible入門
ChefユーザのためのAnsible入門ChefユーザのためのAnsible入門
ChefユーザのためのAnsible入門
 
5人と5万円で 2人が救えた話
5人と5万円で 2人が救えた話5人と5万円で 2人が救えた話
5人と5万円で 2人が救えた話
 
社外セキュリティコンテストへのチャレンジ結果報告
社外セキュリティコンテストへのチャレンジ結果報告社外セキュリティコンテストへのチャレンジ結果報告
社外セキュリティコンテストへのチャレンジ結果報告
 
SQLアンチパターン読書会 レジュメ
SQLアンチパターン読書会 レジュメSQLアンチパターン読書会 レジュメ
SQLアンチパターン読書会 レジュメ
 
Haskell 6-module
Haskell 6-moduleHaskell 6-module
Haskell 6-module
 
最新技術動向(2011年上期)
最新技術動向(2011年上期)最新技術動向(2011年上期)
最新技術動向(2011年上期)
 

Recently uploaded

Recently uploaded (10)

Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 

BigDataの集め方

  • 1. BigDataの集め方 RubyでTwitter Streaming APIを使ってみた @Mahito 12年7月30日月曜日
  • 2. 自己紹介 { 名前 : まひと ID : @Mahito 仕事 : [仮想化, NoSQL, BigData] コミュニティ : [Ruby, MongoDB] 趣味 : [釣り, 熱帯魚, 温泉, 勉強会] } 12年7月30日月曜日
  • 3. 本日のお話 簡単なBigDataの集め方と して、Twitterからのデー タ収集方法と利用サンプル のご紹介 12年7月30日月曜日
  • 4. BigData時代到来! 富、名声、力、この世のすべてを手に入れた 男、海賊王ゴールド・D・ロジャー。彼の死に際 に放った一言は、人々をデータの海へ駆り立て た。 「オレの利益か?欲しけりゃくれてやる。探せ! この世のすべてをそこへ置いてきた!!」 男たちは会社の利益を目指し、様々なデータを追 い続ける。 世はまさに、BigData時代!! 12年7月30日月曜日
  • 5.             |i      \      |.| 長いので一言で       ト\   /| ト       | トヽ   / | | ト       | | トヽ\/| | | ト    /       | | | ト\≧三ミゞ=イ/      ム彡''´ ̄ ̄    ̄ ヽ{__..     /             V´     ノ  __          ',  ,. == y ̄, __、\_        )  |i  }-| ゝ二 |/ ̄ ̄  /ニ,l  ヽ__ノ/ヾ _ ノ       > }} 世界的ですもんね   / >≦'__        し /    Vて二オカ       (_,/}    Yこ二ノ!!|          } 乗るしかない     Y͡ 从        ∠)     从从从トミ   _.ィニ二 ̄丶      ミ三三彡 ' ´      \ \ このビッグデータに         /           \ヽ       /            ミ;,. ', ',        |   _  _ __    \',.',       ノ!   | V7\ ´/      / l /_ゝ| ト >__/ /      |   ヽン ´  ヽー'     i|                l     |:! ヽ              | 12年7月30日月曜日     | ト、 `ミ,            l
  • 6. そもそもBigDataって? BigData自体の定義は曖昧 データの大きさ データの種類 データ構造が半構造や非構造 ソーシャルサービスのデータやそれらの複数 の組み合わせが例にあげられる 12年7月30日月曜日
  • 7. どうやって集めるの? そこでTwitterですよ! 12年7月30日月曜日
  • 8. ご存知とは思いますが Twitter 12年7月30日月曜日
  • 9. Twitter 5億ユーザ(アクティブユーザは1.4億) 1日あたり4.9億 tweet(日本5970万 tweet) 1秒辺り7000 tweet(日本1400 tweet) 余談 2011年12月9日に放送された「天空の城ラピュ タ」の「バルス」の瞬間に25088 tweet/sで当時 の最高記録を樹立 12年7月30日月曜日
  • 10. 先週の状況 サマーウォーズ 12年7月30日月曜日
  • 11. REST APIでデータ収集 Twitterにはデータ取得用のREST APIが存在 Requestに応じてJSON形式でデータ取得可能 それらをWrappingしたライブラリも存在 Twitter4J(Java) Twitter(Ruby) Twitter4R(Ruby) TwitterクライアントのほとんどはREST APIで 実装されている(模様) 12年7月30日月曜日
  • 12. REST APIでデータ収集? REST APIでデータ収集できないことはない ただし制限として350 request / hour Public Time Lineの情報は20 tweet/request さらに60秒間キャッシュが効いているため、 1200 tweet / hourが限界 12年7月30日月曜日
  • 13. そこでStreaming APIですよ APIを利用するとTwitter側からデータが自動 的に送られてくる(Push式) APIの使用制限がない Streaming APIの種類は3つ Public Stream(Public Time Line) User Stream(特定のユーザ対象) Site Stream(Webサイト向け) 12年7月30日月曜日
  • 14. Public Stream Public Streamにも3つの種類が存在 filter(フィルタリングしたPublic TL) sample(Public TLの一部) firehose(一部企業向け) 12年7月30日月曜日
  • 15. ブラウザでお試し 以下のURLにアクセス https://stream.twitter.com/1/statuses/sample.json 自分のTwitterIDとパスワードを入力 (Basic認証) DLが開始される (終わらないので満足したら止めること!) 12年7月30日月曜日
  • 16. Rubyでお試し OAuthの設定 Twitter Developersのサイトで実施 https://dev.twitter.com/ サインイン My Application Create a new Application 入力フォームを埋めて各種Keyを入手 12年7月30日月曜日
  • 17. Rubyでお試し Rubyのライブラリ”TweetStream”を利用 https://github.com/intridea/tweetstream/ “gem install tweetstream”でインストール TweetStreamのサンプルにそってコーディング 12年7月30日月曜日
  • 18. サンプルコード(sample) 1 require 'tweetstream' 2 require 'yaml' 3 4 CONF = YAML::load(open("conf.yaml")) 5 6 TweetStream.configure do |config| 7 config.consumer_key = CONF["consumer_key"] 8 config.consumer_secret = CONF["consumer_secret"] 9 config.oauth_token = CONF["token"] 10 config.oauth_token_secret = CONF["token_secret"] 11 config.auth_method = :oauth 12 end 13 14 TweetStream::Client.new.sample do |status| 15 puts status.text 16 end 12年7月30日月曜日
  • 19. サンプルコード(filter) 1 require 'tweetstream' 2 require 'yaml' 3 4 CONF = YAML::load(open("conf.yaml")) 5 6 TweetStream.configure do |config| 7 config.consumer_key = CONF["consumer_key"] 8 config.consumer_secret = CONF["consumer_secret"] 9 config.oauth_token = CONF["token"] 10 config.oauth_token_secret = CONF["token_secret"] 11 config.auth_method = :oauth 12 end 13 14 TweetStream::Client.new.track('Ruby') do |status| 15 puts status.text 16 end 12年7月30日月曜日
  • 20. 取得データ(1件) {"in_reply_to_user_id_str"=>"455267413", "place"=>nil, "text"=>"@AsantiWheels keep a look out for "Ruby" @SEMASHOW this year http:/ /t.co/mDUGAJlR", "contributors"=>nil, "in_reply_to_user_id"=>455267413, "id_str"=>"227440608116097024", "coordinates"=>nil, "geo"=>nil, "favorited"=>false, "source"=>"<a href="http:/ / twitter.com/download/android" rel="nofollow">Twitter for Android</a>", "possibly_sensitive_editable"=>true, "created_at"=>"Mon Jul 23 16:30:42 +0000 2012", "in_reply_to_screen_name"=>"AsantiWheels", "in_reply_to_status_id"=>nil, "possibly_sensitive"=>false, "in_reply_to_status_id_str"=>nil, "user"=>{"is_translator"=>false, "notifications"=>nil, "profile_use_background_image"=>true, "profile_background_image_url_https"=>"https:/ / si0.twimg.com/images/themes/theme1/bg.png", "time_zone"=>nil, "profile_text_color"=>"333333", "profile_image_url_https"=>"https:/ /si0.twimg.com/profile_images/2386225418/549WvyXy_normal", "following"=>nil, "verified"=>false, "profile_background_image_url"=>"http:/ /a0.twimg.com/images/themes/theme1/bg.png", "default_profile_image"=>false, "profile_link_color"=>"0084B4", "description"=>"car crazy Arizona guy, dodge parts monkey, Severed Ties O.G. member, owner of Chain Reaction ", "id_str"=>"576656522", "contributors_enabled"=>false, "geo_enabled"=>false, "favourites_count"=>0, "followers_count"=>26, "profile_image_url"=>"http:/ /a0.twimg.com/ profile_images/2386225418/549WvyXy_normal", "follow_request_sent"=>nil, "created_at"=>"Thu May 10 23:21:38 +0000 2012", "profile_background_color"=>"C0DEED", "profile_background_tile"=>false, "friends_count"=>184, "url"=>nil, "show_all_inline_media"=>false, "statuses_count"=>99, "profile_sidebar_fill_color"=>"DDEEF6", "protected"=>false, "screen_name"=>"Severed_Joe", "listed_count"=>0, "name"=>"J.M.", "profile_sidebar_border_color"=>"C0DEED", "location"=>"Phx, AZ", "id"=>576656522, "default_profile"=>true, "lang"=>"en", "utc_offset"=>nil}, "retweet_count"=>0, "id"=>227440608116097024, "entities"=>{"user_mentions"=>[{"indices"=>[0, 13], "id_str"=>"455267413", "screen_name"=>"AsantiWheels", "name"=>"Asanti Wheels", "id"=>455267413}, {"indices"=>[41, 50], "id_str"=>"21902226", "screen_name"=>"SEMASHOW", "name"=>"SEMA Show", "id"=>21902226}], "media"=>[{"type"=>"photo", "indices"=>[61, 81], "display_url"=>"pic.twitter.com/mDUGAJlR", "media_url_https"=>"https:/ /p.twimg.com/AygIBy6CQAA2O3i.jpg", "id_str"=>"227440608120291328", "sizes"=>{"small"=>{"resize"=>"fit", "h"=>680, "w"=>284}, "medium"=>{"resize"=>"fit", "h"=>1172, "w"=>490}, "large"=>{"resize"=>"fit", "h"=>1172, "w"=>490}, "thumb"=>{"resize"=>"crop", "h"=>150, "w"=>150}}, "url"=>"http://t.co/mDUGAJlR", "expanded_url"=>"http:/ /twitter.com/Severed_Joe/status/227440608116097024/photo/1", "media_url"=>"http:/ /p.twimg.com/AygIBy6CQAA2O3i.jpg", "id"=>227440608120291328}], "hashtags"=>[], "urls"=>[]}, "retweeted"=>false, "truncated"=>false} 12年7月30日月曜日
  • 21. まとめ Twitter Streaming APIは簡単に利用できる Twitter Streaming APIを利用することで、だ れでも簡単にBigDataを入手することができる BigDataで勝ち残るポイントは データを蓄積すること 蓄積したデータを活かすかこと 12年7月30日月曜日