Created
February 28, 2017 12:11
-
-
Save marceloinacio/1a876a80a3a99aa1a51fa1212156ba58 to your computer and use it in GitHub Desktop.
Publish Java sample (JSONObject and JSONArray)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSONArray position = new JSONArray(); | |
position.put(32L); | |
System.out.println("before pub: " + position); | |
pubnub.publish() | |
.message(position.toList()) | |
.channel("my_channel") | |
.async(new PNCallback<PNPublishResult>() { | |
@Override | |
public void onResponse(PNPublishResult result, PNStatus status) { | |
// handle publish result, status always present, result if successful | |
// status.isError to see if error happened | |
if(!status.isError()) { | |
System.out.println("pub timetoken: " + result.getTimetoken()); | |
} | |
System.out.println("pub status code: " + status.getStatusCode()); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSONObject position = new JSONObject(); | |
position.put("lat", 32L); | |
position.put("lng", 32L); | |
System.out.println("before pub: " + position); | |
pubnub.publish() | |
.message(position.toMap()) | |
.channel("my_channel") | |
.async(new PNCallback<PNPublishResult>() { | |
@Override | |
public void onResponse(PNPublishResult result, PNStatus status) { | |
// handle publish result, status always present, result if successful | |
// status.isError to see if error happened | |
if(!status.isError()) { | |
System.out.println("pub timetoken: " + result.getTimetoken()); | |
} | |
System.out.println("pub status code: " + status.getStatusCode()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment