Using the Streaming API

The Streaming API allows developers to integrate real-time streaming data into their applications. Live results and twitter commentary are delivered via a websocket connection for all supported live events.

Sample Twitter Stream

A simple example of using the Twitter Stream is available here.

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <title>Streaming API Websocket Twitter Example</title>
    <meta name="description" content="Streaming API Websocket Twitter Example">
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="">
    <!--[if lt IE 9]>
    <script src="//"></script>
<div class="container">
    <h1>Streaming API Websocket Twitter Example</h1>
    <div class="row">
        <div class="col-md-12">
            <h2>Latest Tweets</h2>
            <table class="table table-bordered table-hover table-striped" id="timing_table">
                    <th>Profile Image</th>
                <tr id="waiting">
                    <td colspan="6">Waiting for the next tweet to arrive...</td>
    <p>This code is for demonstration purposes and should not be used in a production environment.</p>
<script src=""></script>
<script src=""></script>
<!-- Script to utilise the WebSocket -->
<script type="text/javascript">
    var webSocket;

    function openSocket(){
        // Ensures only one connection is open at a time
        if(webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED){
            writeResponse("WebSocket is already opened.");

        // Create a new instance of the websocket
        webSocket = new WebSocket("wss://");

        webSocket.onopen = function(event){
            console.log('Websocket connection open');

        webSocket.onmessage = function(event){
            var e = jQuery.parseJSON( );

            var t = e.created_at,
                n = moment(t).format("h:mm a"),
                p = "<img width='32px' height='32px' src='" + e.user.profile_image_url + "'/>";
                r = "<tr><td>" + n + "</td><td>" + + "</td><td>" + p + "</td><td>" + e.tweet + "</td><td>" + e.source + "</td></tr>";

            $("#timing_table tbody").prepend(r);


    //Open the socket

A simple example of using the Live Timing websocket feed is available here.