Skip to content

Instantly share code, notes, and snippets.

@posaunehm
Last active August 29, 2015 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save posaunehm/b5cb36b54ae5e6b5cbb9 to your computer and use it in GitHub Desktop.
Save posaunehm/b5cb36b54ae5e6b5cbb9 to your computer and use it in GitHub Desktop.
An sample method for Typetalk api with C# (https://developer.nulab-inc.com/docs/typetalk)
// Refer follwing modules:
// using System.Collections.Generic;
// using System.Net.Http;
// using System.Web.Script.Serialization;
private async void Application_Startup(object sender, StartupEventArgs e)
{
var clientId = "xxxxxxxxxxxx";
var clientSecret = "xxxxxxxxxxxxxxx";
var topicId = 0; //use your topic id
var client = new HttpClient();
var content = new FormUrlEncodedContent(new Dictionary<string,string>() {
{ "client_id", clientId },
{ "client_secret", clientSecret },
{ "grant_type", "client_credentials" },
{ "scope", "topic.post" }
});
await client.PostAsync("https://typetalk.in/oauth2/access_token", content).ContinueWith(res =>
{
var str = res.Result.Content.ReadAsStringAsync().Result;
var dic = new JavaScriptSerializer().Deserialize<Dictionary<string,string >> (str);
var accessToken = dic["access_token"];
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
return client.PostAsync("https://typetalk.in/api/v1/topics/" + topicId,
new FormUrlEncodedContent(new Dictionary<string,string>() { { "message", "Hello, Typetalk!" } })).Result;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment