Qik is a service of streaming (broadcasting) and video downloads from mobile phones. The downloaded video can be viewed on the
website or on its
special version from a mobile phone. Integration with other services such as Twitter, Facebook and others is available. Clients for almost all modern phone models: iPhone, Windows Mobile, Symbian, Android, Blackberry and others.
Qik Push Engine is a mechanism that allows you to receive instant notifications about new / changed Qik-videos. For example, you can watch a constantly updated list of live videos, all videos from the Novoperedelkino area, or all videos with the word “cat”. Based on the Qik Push Engine API, you can build interesting applications integrated with Qik, or add functionality to existing ones. You can write your own notification system, desktop-widget
or something else.
Today we open API for working with Qik Push Engine. This is the first sign in the large list of APIs that open access to the Qik streaming platform. If you are interested in seeing Qik Push Engine in action, go to one of the
sample pages .
API Basics
Qik Push Engine API is available as a set of remote procedures via JSON-RPC (over HTTP). In the near future, a REST-like interface will be open. The entry point for JSON-RPC is
engine.qik.com/api/jsonrpc . While the project is in closed beta testing, you need to specify the developer key by accessing the apikey parameter:
engine.qik.com/api/jsonrpc?apikey=xxxxxxx . The developer key can be obtained by sending an email with a request to
api@qik.com .
')
Example HTTP session:
POST /api/jsonrpc Host : engine.stage.qik.com Content-Type: application/json; charset=UTF-8 Content-Length: 46 {"method": "qik.session.create", "params": []}
Answer:
Content-Type: text/json ["a56c1603-1fbb-4140-8b35-8c36abbd8b27"]
Example of subscribing to event stream
Hereinafter, I will use a simple command call entry, which is similar to a call to ordinary functions, omitting the details of JSON-RPC interaction. So, let us want to subscribe to the list of all live streams that are currently in effect.
First of all, create a session:
qik.session.create() -> "a56c1603-1fbb-4140-8b35-8c36abbd8b27"
Subscribe within the session to view all public live streams, while specifying the maximum number of elements in the view (limit). View elements will be ordered in decreasing order of the start date of the stream (the newest first):
qik.stream.subscribe<em>public</em>live("a56c1603-1fbb-4140-8b35-8c36abbd8b27", 10) -> [ "174/('PublicLiveStreamView', 'Stream', [('stoptime', None)], 'alllive;limit=10')", [ ... ] ]
In response to the request, we get an array of two elements: the first is the subscription key (a long string starting with “174 / ..”). Do not look for meaning in the subscription key, you just need to save it, it will be needed in the future.
The second element is the initial view state, that is, the current list of live streams in our case. We will receive no more than 10 elements (since we specified limit 10 when calling the
qik.stream.subscribe_public_live
method). The view state looks something like this:
[ {"url": "http://qik.com/video/2158468", "live": true, "user_id": 340699, "small_thumbnail_url": "http://media.qik.com/media.thumbnails.128/c8ad8fe065ad4ad7ac8491874c043eac.jpg", "title": "Untitled", "duration": 0, "created_at": "2009-07-11 15:56:03", "views": 0, "id": 2158468}, {"url": "http://qik.com/video/2158466", "live": true, "user_id": 340119, "small_thumbnail_url": "http://media.qik.com/media.thumbnails.128/984c33e1ead441038f315e1fff109fc5.jpg", "title": "Testando!", "duration": 0, "created_at": "2009-07-11 15:55:34", "views": 0, "id": 2158466} ]
The meaning of most fields is obvious, I will give only some comments:
- all dates are in UTC;
- the
duration
field stores the video duration in seconds.
Since we subscribed to the live stream, all videos have
live == true
.
Now we need to receive new events for those view to which we have subscribed. HTTP long polling requests are used for this. The client sends a request to the server, and the server sends a response when events occur or when the timeout expires, if no events occurred.
To implement long polling in a loop, call the
qik.session.get_events
method, specifying the desired timeout (it is not recommended to use a timeout longer than 90 seconds).
qik.session.get_events("a56c1603-1fbb-4140-8b35-8c36abbd8b27", 60) -> [ {...} ,{...} ]
In response, we can get an empty array of events if the timeout has expired, or some set of events of the following form:
[ { "action": "update", "old": {"id": 104252, "title": "Untitled", "views": 0, ...}, "obj": {"id": 104252, "title": "driving to key largo", "views": 5, ...}, "key": "175/('PublicRecentStreamView', 'Stream', [], 'allrecent;limit=50')" }, ]
In each event, the following information is transmitted:
key
- subscription key, this is the same value that we received when subscribing to the view, the key allows you to distinguish events for different views within the same session;action
- the action (change) that occurred with the view:
ping
- nothing happened, just the view says that everything is fine 
update
- the view element has changed (as in the example above), the old and new state of the object is transmitted in the old
and obj
fieldsinsert
- a new element has been added to the view, its state will be written to the obj
fielddelete
- the element disappeared from the view (maybe the video was deleted, or simply ceased to meet the criteria of view, or went beyond the “limit” boundary), the last state of the object will be recorded in the obj
field.
- abstract class representing view on the client side. Service updates, display in HTML elements, event handling, etc. Element lists are stored directly in the DOM container as HTML nodes.
The descendants of
QikEngine.View
to implement a specific view:
QikEngine.PublicUserStreamView
,
QikEngine.PublicRecentStreamsView
, etc.
A very simple interface between data obtained from Qik Push Engine (for example, information about streams) and HTML elements. Adapt data, such as converting dates from UTC to a local format, formatting values, etc.
QikEngine.UserCache
is a mechanism for downloading information about users (by their ID). Uses
DeferredManager
to limit the number of parallel requests.
What to do next?
- see API description ;
- write a letter to api@qik.com, tell us about your project and get the key to access the API.
Full list of examples
In all examples, the video lists are updated automatically when changes are made on the site or from a mobile phone, for example, if I give Vasya access to my private video, he will immediately see this video in the list of my streams, etc.