Publication publicationConf2 = new Publication("conference2", 20d, 2000d);
matchMore.createPublication(publicationConf2, "df8dbde6-326c-49f1-82a1-a5cbffeb1290");
``` (shift+enter for line break)
var code = "formatted";
PinDevice pinDevice = new PinDevice("pinDeviceTransport", new MatchMoreLocation(32L,46.52214476,6.64595656) );
matchMore.createPinDevice(pinDevice, createdPinDevice ->{
Toast.makeText(getApplicationContext(), "pinDevice créé", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "pinDeviceID = " + createdPinDevice.getId(), Toast.LENGTH_SHORT).show();
this.pinID = createdPinDevice.getId();
return Unit.INSTANCE;
}, e -> {
Toast.makeText(getApplicationContext(), "erreur creation pinDevice: " + e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("JavaExample", e.getMessage());
return Unit.INSTANCE;
});
Publication publicationConf = new Publication("conference", 3330d, 3330d);
matchMore.createPublication(publicationConf, pinID, createdPublication ->{
Toast.makeText(getApplicationContext(), "Publication créée", Toast.LENGTH_SHORT).show();
Log.d("TARTATIN", createdPublication.toString());
return Unit.INSTANCE; // return Unit.INSTANCE; is important (b/c kotlin vs java lambdas differ in implementation)
}, e -> {
Toast.makeText(getApplicationContext(), "erreur creation publication: " + e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("JavaExample", e.getMessage());
return Unit.INSTANCE;
});
```
matchMore.createPinDevice(pinDevice, createdPinDevice ->{
Toast.makeText(getApplicationContext(), "pinDevice créé", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "pinDeviceID = " + createdPinDevice.getId(), Toast.LENGTH_SHORT).show();
this.pinID = createdPinDevice.getId();
return Unit.INSTANCE;
}, e -> {
04-16 13:39:55.432 11508-11508/ch.giacomolonghi.unilapp D/pinid: 40bdeb11-b03a-4823-81bb-33b99e5cfbf2
04-16 13:39:55.457 11508-11508/ch.giacomolonghi.unilapp D/TARTATIN: Publication(topic=conference, range=3330.0, duration=3330.0, properties={}, deviceId=448af123-5b92-4b2b-b249-160b57434c2b, worldId=null, createdAt=1523878795430, id=6a564909-871f-403b-9920-82df8bd61c3c)
When there is asynchronous calls, you have to make sure that async call One is finished before async call Two is launched. Especially, when you need a value that is returned with async call One.
In your case, you have pinID which is supposed to be store at the end of the async call One, but if your async call Two is called before async call One is done. Then you will have pinID = null, which lead to the case where createPublication(publication, null) == you create a publication for your main device.
Hi, I'm trying to make a publication from a server in Java. If I understood correctly, I need to make a post request on your rest api using this url: https://api.matchmore.io/v5/devices/{deviceId}/publications
Then I need to replace the brackets of the deviceId by my deviceId. However, I still have the following question: how do I structure the header of the request? Do I only need the api key ? or should I put any username and password encrypted too?
For example taking this code:
´´´
HttpPost createConnectivity(String restUrl, String username, String password)
{
HttpPost post = new HttpPost(restUrl);
String auth=new StringBuffer(apiKey).toString();
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8")));
String authHeader = "Basic " + new String(encodedAuth);
post.setHeader("AUTHORIZATION", authHeader);
post.setHeader("Content-Type", "application/json");
post.setHeader("Accept", "application/json");
post.setHeader("X-Stream" , "true");
return post;
}
´´´
Would it be the correct approach for the header?
Hello, I'm trying to do the same as Arnaud, But I get a HandShake_Failure.
This is my code: Do I need to specify authentication somewhere?
....
public class Test {
public static void main(String[] args) throws IOException {
URL url = new URL("https://api.matchmore.io/v5/devices/{deviceId}/publications");
HttpsURLConnection httpCon = (HttpsURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter(
httpCon.getOutputStream());
System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage());
out.close();
}
}
setHeader("AUTHORIZATION", "<your api key>");