Last active
August 29, 2015 14:07
-
-
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)
This file contains 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
// 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