in sample-code/csharp-pubsub/pubsub-post.cs [16:47]
IEnumerator PostMessage(PinballEvent message)
{
var messages = JObject.FromObject(new
{
messages = new JObject[]
{
JObject.FromObject(message.GetMessage())
}
});
var content = JObject.FromObject(messages).ToString();
var rawContent = Encoding.UTF8.GetBytes(content);
UnityWebRequest client = new UnityWebRequest(PUB_SUB_POST_URL, "POST");
client.SetRequestHeader("Authorization", "Bearer " + accessToken);
client.SetRequestHeader("Content-Type", "application/json; charset=utf-8");
client.uploadHandler = new UploadHandlerRaw(rawContent);
client.downloadHandler = new DownloadHandlerBuffer();
yield return client.Send();
if (client.isError)
{
Multimorphic.P3App.Logging.Logger.LogError("Error posting pubsub message: " + client.error);
}
else
{
var response = client.downloadHandler.text;
Multimorphic.P3App.Logging.Logger.Log("PubSub Message Posted: " + response);
}
}