PubNub History API

This tutorial demonstrates the History API. Use this API to load history of published messages. Up to 100 history messages are available per channel.

PUBNUB.history( args, callback )

This function fetches the history of a channel. History automatically expires in 24-72 hours.

	// Request History
	PUBNUB.history({
	    // Set channel to 'example'
	    channel : 'example',

	    // Set limit of returned
	    limit : 100

		// Set Callback Function when History Returns
	}, function(messages) {

	    // Show History
	    console.log(messages);

	} );

The response is an array of your messages. The History Response returns in the following format:

	[
	    { "my_var" : "some text 2" },
	    { "my_var" : "some text 1" },
	    { "my_var" : "some text 3" }
	]

That's it! Here is a sample application to test:

	PUBNUB.bind( 'mousedown', PUBNUB.$('test'), function() {

	    PUBNUB.publish( {
	        channel : 'my_channel',
	        message : 'Hello World!!!'
	    }, function() {
	        PUBNUB.history( {
	            channel : 'my_channel',
	            limit   : 1
	        }, function(messages) {
	            alert("Message: " + messages[0]);
	        } );
	    } );

	});

This API is great for servering realtime data to web crawlers. Access this API from PHP via the PHP PubNub Client API on GitHub.