The Wayback Machine - https://web.archive.org/web/20120807181156/https://dev.twitter.com/docs/streaming-apis/messages

Streaming message types

Updated on Wed, 2012-06-20 08:35

Public stream messages

In addition to standard Tweet payloads, the following kinds of messages may be delivered on a stream. Note that this list may not be comprehensive—additional objects may be introduced into streams in the future. Ensure that your parser is tolerant of unexpected message formats.

When parsing Tweets, keep in mind that Retweets are streamed as a status with another status nested inside it. If you are matching Tweet fields using regular expressions, it is possible that you will match fields in the nested Tweet instead of the wrapper. As a rule of thumb it is better to use a JSON parser to extract information from message payloads.

Blank lines

On slow streams, some messages may be blank lines which serve as "keep-alive" signals to prevent clients and other network infrastructure from assuming the stream has stalled and closing the connection.

Status deletion notices (delete)

These messages indicate that a given Tweet has been deleted. Client code must honor these messages by clearing the referenced Tweet from memory and any storage or archive, even in the rare case where a deletion message arrives earlier in the stream that the Tweet it references.

{
  "delete":{
    "status":{
      "id":1234,
      "id_str":"1234",
      "user_id":3,
      "user_id_str":"3"
    }
  }
}

Location deletion notices (scrub_geo)

These messages indicate that geolocated data must be stripped from a range of Tweets. Clients must honor these messages by deleting geocoded data from Tweets which fall before the given status ID and belong to the specified user. These messages may also arrive before a Tweet which falls into the specified range, although this is rare.

{
  "scrub_geo":{
    "user_id":14090452,
    "user_id_str":"14090452",
    "up_to_status_id":23260136625,
    "up_to_status_id_str":"23260136625"
  }
}

Limit notices (limit)

These messages indicate that a filtered stream has matched more Tweets than its current rate limit allows to be delivered. Limit notices contain a total count of the number of undelivered Tweets since the connection was opened, making them useful for tracking counts of track terms, for example. Note that the counts do not specify which filter predicates undelivered messages matched.

{
  "limit":{
    "track":1234
  }
}

Withheld content notices (status_withheld, user_withheld)

These messages indicate that either the indicated tweet or indicated user has had their content withheld (see New Withheld Content Fields in API Responses for more information).

status_withheld

These events contain an id field indicating the status ID, a user_id indicating the user, and a collection of withheld_in_countries two-letter country codes. This example illustrates a hypothetical tweet that has been withheld in Germany and Argentina.

{
  "status_withheld":{
      "id":1234567890,
      "user_id":123456,
      "withheld_in_countries":["de", "ar"]
  }
}

user_withheld

These events contain an id field indicating the user ID and a collection of withheld_in_countries two-letter country codes. This example illustrates a hypothetical user who has been withheld in Germany and Argentina.

{  
  "user_withheld":{
    "id":123456,
    "withheld_in_countries":["de","ar"]
  }
}

User stream messages

Friends lists (friends)

Upon establishing a User Stream connection, Twitter will send a preamble before starting regular message delivery. This preamble contains a list of the user’s friends. This is represented as an array of user ids, for example:

{
  "friends":[
    1497,
    169686021,
    790205,
    15211564,
    ...
  ]
}

This message will only be sent once per connection.

Events (event)

Notifications about non-Tweet events are also sent over a user stream. These generally have the form of:

{
  "target": TARGET_USER,
  "source": SOURCE_USER, 
  "event":"EVENT_NAME",
  "target_object": TARGET_OBJECT,
  "created_at": "Sat Sep 4 16:10:54 +0000 2010"
}

The values present will be different based on the type of event. The following types of events are streamed:

DescriptionEvent NameSourceTargetTarget Object
User blocks someone block Current user Blocked user Null
User removes a block unblock Current user Unblocked user Null
User favorites a Tweet favorite Current user Tweet author Tweet
User's Tweet is favorited favorite Favoriting user Current user Tweet
User unfavorites a Tweet unfavorite Current user Tweet author Tweet
User's Tweet is unfavorited unfavorite Unfavoriting user Current user Tweet
User follows someone follow Current user Followed user Null
User is followed follow Following user Current user Null
User creates a list list_created Current user Current user List
User deletes a list list_destroyed Current user Current user List
User edits a list list_updated Current user Current user List
User adds someone to a list list_member_added Current user Added user List
User is added to a list list_member_added Adding user Current user List
User removes someone from a list list_member_removed Current user Removed user List
User is removed from a list list_member_removed Removing user Current user List
User subscribes to a list list_user_subscribed Current user List owner List
User's list is subscribed to list_user_subscribed Subscribing user Current user List
User unsubscribes from a list list_user_unsubscribed Current user List owner List
User's list is unsubscribed from list_user_unsubscribed Unsubscribing user Current user List
User updates their profile user_update Current user Current user Null

Site stream messages

Envelopes (for_user)

Site Streams are sent the same messages as User Streams (including friends lists in the preamble), but for multiple users instead of a single user. The same types of messages are streamed, but to identify the target of each message, an additional wrapper is placed around every message, except for blank keep-alive lines. The Site Streams messages for two friends lists would look like:

{
  "for_user":"1888",
  "message":{"friends":[]}
}
{
  "for_user":"9160152",
  "message":{"friends":[]}
}

If a message should be routed to multiple users, multiple wrapped messages will be sent, each with a different for_user value.

Control messages (control)

Upon establishing a Site Streams connection, Twitter will send a preamble before starting regular message delivery. This preamble will contain a control message which may be used to modify the Site Streams connection without reconnecting. See Control Streams for Site Streams for details.

{
  "control":{
    "control_uri": "/2b/site/c/01_225167_334389048B872A533002B34D73F8C29FD09EFC50"
  }
}