java/srcPubnubApi/com/pubnub/api/PubnubCore.java
/**
     *
     * Read History for a channel.
     *
     * @param channel
     *            Channel name for which history is required
     * @param start
     *            Start time
     * @param end
     *            End time
     * @param count
     *            Upper limit on number of messages to be returned
     * @param reverse
     *            True if messages need to be in reverse order
     * @param includeTimetoken
     *            True/False whether to include timetokens in response
     * @param callback
     *            Callback
     */
Read History for a channel.
Read History for a channel .
public void history(final String channel, long start, long end,
            int count, boolean reverse, boolean includeTimetoken, Callback callback) {
        final Callback cb = getWrappedCallback(callback);
        Hashtable parameters = PubnubUtil.hashtableClone(params);
        if (count == -1)
            count = 100;
        parameters.put("count", String.valueOf(count));
        parameters.put("reverse", String.valueOf(reverse));
        parameters.put("include_token", String.valueOf(includeTimetoken));
        if (start != -1)
            parameters.put("start", Long.toString(start).toLowerCase());
        if (end != -1)
            parameters.put("end", Long.toString(end).toLowerCase());
        String[] urlargs = { getPubnubUrl(), "v2", "history", "sub-key",
                this.SUBSCRIBE_KEY, "channel", PubnubUtil.urlEncode(channel)
        };
        class HistoryResponseHandler extends ResponseHandler {
            public void handleResponse(HttpRequest hreq, String response) {
                JSONArray respArr;
                try {
                    respArr = new JSONArray(response);
                    decryptJSONArray((JSONArray) respArr.get(0));
                    cb.successCallback(channel, respArr);
                } catch (JSONException e) {
                    cb.errorCallback(channel,
                            PubnubError.getErrorObject(PubnubError.PNERROBJ_JSON_ERROR, 3));
                } catch (IOException e) {
                    cb.errorCallback(channel,
                            PubnubError.getErrorObject(PubnubError.PNERROBJ_DECRYPTION_ERROR, 9, response));
                } catch (PubnubException e) {
                    cb.errorCallback(channel, getPubnubError(e, PubnubError.PNERROBJ_DECRYPTION_ERROR, 10, response + " : " + e.toString()));
                } catch (Exception e) {
                    cb.errorCallback(channel,
                            PubnubError.getErrorObject(PubnubError.PNERROBJ_DECRYPTION_ERROR, 11, response + " : " + e.toString()));
                }
            }
            public void handleError(HttpRequest hreq, PubnubError error) {
                cb.errorCallback(channel, error);
                return;
            }
        }
        HttpRequest hreq = new HttpRequest(urlargs, parameters, new HistoryResponseHandler());
        _request(hreq, nonSubscribeManager);
    }
public void history ( final String channel , long start , long end , int count , boolean reverse , boolean includeTimetoken , Callback callback ) { final Callback cb = getWrappedCallback ( callback ) ; Hashtable parameters = PubnubUtil . hashtableClone ( params ) ; if ( count == - 1 ) count = 100 ; parameters . put ( "count" , String . valueOf ( count ) ) ; parameters . put ( "reverse" , String . valueOf ( reverse ) ) ; parameters . put ( "include_token" , String . valueOf ( includeTimetoken ) ) ; if ( start != - 1 ) parameters . put ( "start" , Long . toString ( start ) . toLowerCase ( ) ) ; if ( end != - 1 ) parameters . put ( "end" , Long . toString ( end ) . toLowerCase ( ) ) ; String [ ] urlargs = { getPubnubUrl ( ) , "v2" , "history" , "sub-key" , this . SUBSCRIBE_KEY , "channel" , PubnubUtil . urlEncode ( channel ) } ; class HistoryResponseHandler extends ResponseHandler { public void handleResponse ( HttpRequest hreq , String response ) { JSONArray respArr ; try { respArr = new JSONArray ( response ) ; decryptJSONArray ( ( JSONArray ) respArr . get ( 0 ) ) ; cb . successCallback ( channel , respArr ) ; } catch ( JSONException e ) { cb . errorCallback ( channel , PubnubError . getErrorObject ( PubnubError . PNERROBJ_JSON_ERROR , 3 ) ) ; } catch ( IOException e ) { cb . errorCallback ( channel , PubnubError . getErrorObject ( PubnubError . PNERROBJ_DECRYPTION_ERROR , 9 , response ) ) ; } catch ( PubnubException e ) { cb . errorCallback ( channel , getPubnubError ( e , PubnubError . PNERROBJ_DECRYPTION_ERROR , 10 , response + " : " + e . toString ( ) ) ) ; } catch ( Exception e ) { cb . errorCallback ( channel , PubnubError . getErrorObject ( PubnubError . PNERROBJ_DECRYPTION_ERROR , 11 , response + " : " + e . toString ( ) ) ) ; } } public void handleError ( HttpRequest hreq , PubnubError error ) { cb . errorCallback ( channel , error ) ; return ; } } HttpRequest hreq = new HttpRequest ( urlargs , parameters , new HistoryResponseHandler ( ) ) ; _request ( hreq , nonSubscribeManager ) ; }
Read History for a channel.
Read History for a channel .