in code/PublishToEmbeddedSocial/EmbeddedSocial/EmbeddedSocial.cs [181:225]
private async Task UpdateTopic(string topicName, string topicTitle, string topicText, string topicCategory)
{
// get the handle for the topic name
HttpOperationResponse<GetTopicByNameResponse> getTopicByNameOperationResponse = await this.client.Topics.GetTopicByNameWithHttpMessagesAsync(topicName: topicName, publisherType: PublisherType.App, authorization: this.authorization);
// check response
if (getTopicByNameOperationResponse == null || getTopicByNameOperationResponse.Response == null)
{
throw new Exception("got null response");
}
else if (!getTopicByNameOperationResponse.Response.IsSuccessStatusCode)
{
throw new Exception("request failed with HTTP code: " + getTopicByNameOperationResponse.Response.StatusCode + ", and reason: " + getTopicByNameOperationResponse.Response.ReasonPhrase);
}
else if (getTopicByNameOperationResponse.Body == null)
{
throw new Exception("got null response body");
}
else if (string.IsNullOrWhiteSpace(getTopicByNameOperationResponse.Body.TopicHandle))
{
throw new Exception("topicHandle is null or whitespace");
}
// format the updated topic request
string topicHandle = getTopicByNameOperationResponse.Body.TopicHandle;
PutTopicRequest updatedTopic = new PutTopicRequest()
{
Text = topicText,
Title = topicTitle,
Categories = topicCategory,
};
// submit the updated topic request
HttpOperationResponse putTopicOperationResponse = await this.client.Topics.PutTopicWithHttpMessagesAsync(topicHandle: topicHandle, request: updatedTopic, authorization: this.authorization);
// check response
if (putTopicOperationResponse == null || putTopicOperationResponse.Response == null)
{
throw new Exception("got null response");
}
else if (!putTopicOperationResponse.Response.IsSuccessStatusCode)
{
throw new Exception("request failed with HTTP code: " + putTopicOperationResponse.Response.StatusCode + ", and reason: " + putTopicOperationResponse.Response.ReasonPhrase);
}
}