Introduction
In ScrumPilot, I plan to replace my native news feed by a Yammer news feed; additionally, I want to allow people who don't have Team Foundation Server accounts the possibility view this news feed.
I wrote this API wrapper to interact easily with Yammer.
or just use it
@nuget : Yammer.SimpleAPI package
I wrote this API wrapper to interact easily with Yammer.
Codes sources
@ CodePlex : Yammer.SimpleAPIor just use it
@nuget : Yammer.SimpleAPI package
First Step
In order to use Yammer API, you must setup your app in "My Apps" in Yammer.Below is screen shot of my own app setup: ScrumPilot.
Note at the bottom of the form, the URL redirection to a local address, if you want to interact with your dev environment.
Example
In VS Solution, I added an MVC project for this example.
First Screen
First screen shot, when you run the MVC site, you will see a form where you should type your Yammer Client ID and Client Secret given to you by Yammer when you setup your app.
Post in Controller
It's a very classic Post. it prepares an object with all of the information and it redirects to Yammer with some of the information (see source code below for details).
It retains connection information in Session in case of success (when it comes back from Yammer).
It retains connection information in Session in case of success (when it comes back from Yammer).
[HttpPost] public ActionResult Index(IndexViewModel model) { if (ModelState.IsValid) { // prepare info for Yammer var myConfig = new ClientConfigurationContainer { ClientCode = null, ClientId = model.ClientId, ClientSecret = model.ClientSecret, // especially where it should return // after auth RedirectUri = Request.Url.AbsoluteUri + Url.Action("AuthCode") }; // Create a new Rest Client var myYammer = new YammerClient(myConfig); // Make the right Yammer Url var url = myYammer.GetLoginLinkUri(); // Save data in Session this.TempData["YammerConfig"] = myConfig; // go to Yammer return Redirect(url); } return View(model); }
If everything is correct, you should see the screen shot below; it asks you to authorize Yammer to share information with your app (in my case: ScrumPilot).
When you have clicked on "Allow", Yammer returns to your app, and provides it an authorization code.
To better understand this workflow, read the oauth2 website.
Result and Interactions
// Call back by Yammer when you allow your app // interact with it public ActionResult AuthCode(String code) { // I receive auth code from Yammer if (!String.IsNullOrWhiteSpace(code)) { var myConfig = this.TempData["YammerConfig"] as ClientConfigurationContainer; myConfig.ClientCode = code; var myYammer = new YammerClient(myConfig); // Some examples // var yammerToken = myYammer.GetToken(); // var l = myYammer .GetUsers(); // var t = myYammer .GetImpersonateTokens(); // var i = myYammer .SendInvitation("test@test.fr"); // var m = myYammer .PostMessage("A test from here", // 0, "Event" topic); return View(myYammer.GetUserInfo()); } return null; }
A result example: