forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistoryExample.java
More file actions
50 lines (41 loc) · 1.51 KB
/
Copy pathHistoryExample.java
File metadata and controls
50 lines (41 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package examples;
import java.util.HashMap;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONObject;
import pubnub.Pubnub;
public class HistoryExample {
public static void main(String[] params) {
String pub_key = "demo", sub_key = "demo";
String secret_key = "demo", cipher_key = "";
String channel = "hello_world";
int limit = 4;
Pubnub pubnub = new Pubnub(pub_key, sub_key, secret_key, cipher_key,
true); //(Cipher key is Optional)
HashMap<String, Object> args = new HashMap<String, Object>(2);
args.put("channel", channel);
args.put("limit", limit);
// Get History
JSONArray response = pubnub.history(args);
// Print Response from PubNub JSONP REST Service
System.out.println(response);
try {
if (response != null) {
for (int i = 0; i < response.length(); i++) {
JSONObject jsono = response.optJSONObject(i);
if (jsono != null) {
@SuppressWarnings("rawtypes")
Iterator keys = jsono.keys();
while (keys.hasNext()) {
System.out.print(jsono.get(keys.next().toString())
+ " ");
}
}
System.out.println();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}