{"id":5582,"date":"2013-02-21T04:52:33","date_gmt":"2013-02-21T04:52:33","guid":{"rendered":"http:\/\/zerokidz.com\/ideas\/?p=5582"},"modified":"2013-02-26T04:42:37","modified_gmt":"2013-02-26T04:42:37","slug":"twitter-streaming-php-decoder-breaks-out-individual-tweets","status":"publish","type":"post","link":"https:\/\/reactivemusic.net\/?p=5582","title":{"rendered":"Twitter streaming php decoder breaks out individual tweets"},"content":{"rendered":"<p>This code was adapted (i.e. stolen verbatim) from a stackoverflow post by drew010<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/10337984\/using-the-curl-output\">http:\/\/stackoverflow.com\/questions\/10337984\/using-the-curl-output<\/a><\/p>\n<p>Here&#8217;s the code. It solves a huge problem for the class of projects which need to grab a large amount of tweets in real time to either save in a database, or trigger some action.<\/p>\n<p>My version of the code is in tkzic\/api\/twitterStream1.php<\/p>\n<pre class=\"brush: php; gutter: true\">&lt;?php\r\n\r\n$USERNAME = &#039;youruser&#039;;\r\n$PASSWORD = &#039;yourpass&#039;;\r\n$QUERY    = &#039;nike&#039;;\r\n\r\n\/**\r\n * Called every time a chunk of data is read, this will be a json encoded message\r\n * \r\n * @param resource $handle The curl handle\r\n * @param string   $data   The data chunk (json message)\r\n *\/\r\nfunction writeCallback($handle, $data)\r\n{\r\n    \/*\r\n    echo &quot;-----------------------------------------------------------\\n&quot;;\r\n    echo $data;\r\n    echo &quot;-----------------------------------------------------------\\n&quot;;\r\n    *\/\r\n\r\n    $json = json_decode($data);\r\n    if (isset($json-&gt;user) &amp;&amp; isset($json-&gt;text)) {\r\n        echo &quot;@{$json-&gt;user-&gt;screen_name}: {$json-&gt;text}\\n\\n&quot;;\r\n    }\r\n\r\n    return strlen($data);\r\n}\r\n\r\n$ch = curl_init();\r\n\r\ncurl_setopt($ch, CURLOPT_URL, &#039;https:\/\/stream.twitter.com\/1\/statuses\/filter.json?track=&#039; . urlencode($QUERY));\r\ncurl_setopt($ch, CURLOPT_USERPWD, &quot;$USERNAME:$PASSWORD&quot;);\r\ncurl_setopt($ch, CURLOPT_WRITEFUNCTION, &#039;writeCallback&#039;);\r\ncurl_setopt($ch, CURLOPT_TIMEOUT, 20); \/\/ disconnect after 20 seconds for testing\r\ncurl_setopt($ch, CURLOPT_VERBOSE, 1);  \/\/ debugging\r\ncurl_setopt($ch, CURLOPT_ENCODING,  &#039;gzip, deflate&#039;); \/\/ req&#039;d to get gzip\r\ncurl_setopt($ch, CURLOPT_USERAGENT, &#039;tstreamer\/1.0&#039;); \/\/ req&#039;d to get gzip\r\n\r\ncurl_exec($ch); \/\/ commence streaming\r\n\r\n$info = curl_getinfo($ch);\r\n\r\nvar_dump($info);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This code was adapted (i.e. stolen verbatim) from a stackoverflow post by drew010 http:\/\/stackoverflow.com\/questions\/10337984\/using-the-curl-output Here&#8217;s the code. It solves a huge problem for the class of projects which need to grab a large amount of tweets in real time to either save in a database, or trigger some action. My version of the code is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/reactivemusic.net\/?p=5582\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Twitter streaming php decoder breaks out individual tweets&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[143],"tags":[161,170,196,190,197,136],"class_list":["post-5582","post","type-post","status-publish","format-standard","hentry","category-interactive-media-art","tag-api","tag-curl","tag-php","tag-portfolio","tag-streaming","tag-twitter"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Twitter streaming php decoder breaks out individual tweets - reactive music<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/reactivemusic.net\/?p=5582\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Twitter streaming php decoder breaks out individual tweets - reactive music\" \/>\n<meta property=\"og:description\" content=\"This code was adapted (i.e. stolen verbatim) from a stackoverflow post by drew010 http:\/\/stackoverflow.com\/questions\/10337984\/using-the-curl-output Here&#8217;s the code. It solves a huge problem for the class of projects which need to grab a large amount of tweets in real time to either save in a database, or trigger some action. My version of the code is &hellip; Continue reading &quot;Twitter streaming php decoder breaks out individual tweets&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/reactivemusic.net\/?p=5582\" \/>\n<meta property=\"og:site_name\" content=\"reactive music\" \/>\n<meta property=\"article:published_time\" content=\"2013-02-21T04:52:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-02-26T04:42:37+00:00\" \/>\n<meta name=\"author\" content=\"Tom Zicarelli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tom Zicarelli\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5582#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5582\"},\"author\":{\"name\":\"Tom Zicarelli\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/56224d281582df7e5518e037ca63e571\"},\"headline\":\"Twitter streaming php decoder breaks out individual tweets\",\"datePublished\":\"2013-02-21T04:52:33+00:00\",\"dateModified\":\"2013-02-26T04:42:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5582\"},\"wordCount\":74,\"keywords\":[\"API\",\"curl\",\"php\",\"portfolio\",\"streaming\",\"Twitter\"],\"articleSection\":[\"interactive media art\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5582\",\"url\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5582\",\"name\":\"Twitter streaming php decoder breaks out individual tweets - reactive music\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#website\"},\"datePublished\":\"2013-02-21T04:52:33+00:00\",\"dateModified\":\"2013-02-26T04:42:37+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/56224d281582df7e5518e037ca63e571\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5582#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/reactivemusic.net\\\/?p=5582\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5582#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/reactivemusic.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Twitter streaming php decoder breaks out individual tweets\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#website\",\"url\":\"https:\\\/\\\/reactivemusic.net\\\/\",\"name\":\"reactive music\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/reactivemusic.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/56224d281582df7e5518e037ca63e571\",\"name\":\"Tom Zicarelli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g\",\"caption\":\"Tom Zicarelli\"},\"sameAs\":[\"http:\\\/\\\/tomzicarelli.com\"],\"url\":\"https:\\\/\\\/reactivemusic.net\\\/?author=2\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Twitter streaming php decoder breaks out individual tweets - reactive music","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/reactivemusic.net\/?p=5582","og_locale":"en_US","og_type":"article","og_title":"Twitter streaming php decoder breaks out individual tweets - reactive music","og_description":"This code was adapted (i.e. stolen verbatim) from a stackoverflow post by drew010 http:\/\/stackoverflow.com\/questions\/10337984\/using-the-curl-output Here&#8217;s the code. It solves a huge problem for the class of projects which need to grab a large amount of tweets in real time to either save in a database, or trigger some action. My version of the code is &hellip; Continue reading \"Twitter streaming php decoder breaks out individual tweets\"","og_url":"https:\/\/reactivemusic.net\/?p=5582","og_site_name":"reactive music","article_published_time":"2013-02-21T04:52:33+00:00","article_modified_time":"2013-02-26T04:42:37+00:00","author":"Tom Zicarelli","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Tom Zicarelli","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/reactivemusic.net\/?p=5582#article","isPartOf":{"@id":"https:\/\/reactivemusic.net\/?p=5582"},"author":{"name":"Tom Zicarelli","@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/56224d281582df7e5518e037ca63e571"},"headline":"Twitter streaming php decoder breaks out individual tweets","datePublished":"2013-02-21T04:52:33+00:00","dateModified":"2013-02-26T04:42:37+00:00","mainEntityOfPage":{"@id":"https:\/\/reactivemusic.net\/?p=5582"},"wordCount":74,"keywords":["API","curl","php","portfolio","streaming","Twitter"],"articleSection":["interactive media art"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/reactivemusic.net\/?p=5582","url":"https:\/\/reactivemusic.net\/?p=5582","name":"Twitter streaming php decoder breaks out individual tweets - reactive music","isPartOf":{"@id":"https:\/\/reactivemusic.net\/#website"},"datePublished":"2013-02-21T04:52:33+00:00","dateModified":"2013-02-26T04:42:37+00:00","author":{"@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/56224d281582df7e5518e037ca63e571"},"breadcrumb":{"@id":"https:\/\/reactivemusic.net\/?p=5582#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/reactivemusic.net\/?p=5582"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/reactivemusic.net\/?p=5582#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/reactivemusic.net\/"},{"@type":"ListItem","position":2,"name":"Twitter streaming php decoder breaks out individual tweets"}]},{"@type":"WebSite","@id":"https:\/\/reactivemusic.net\/#website","url":"https:\/\/reactivemusic.net\/","name":"reactive music","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/reactivemusic.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/56224d281582df7e5518e037ca63e571","name":"Tom Zicarelli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g","caption":"Tom Zicarelli"},"sameAs":["http:\/\/tomzicarelli.com"],"url":"https:\/\/reactivemusic.net\/?author=2"}]}},"_links":{"self":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/5582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5582"}],"version-history":[{"count":7,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/5582\/revisions"}],"predecessor-version":[{"id":5585,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/5582\/revisions\/5585"}],"wp:attachment":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}