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:
What is AuthCode in Url.Action("AuthCode")?
RépondreSupprimerYour sample project doesn't seem to work. I think Yammer changed the authentication method. Could you update the project?
RépondreSupprimerThank you!
Yes, I will do in couple of days
RépondreSupprimerStay tune!
Hi Raynald, any news on the update given the change in authentication method?
RépondreSupprimerLack of time :)
RépondreSupprimerYou could look in this sources code : https://notifypilot.codeplex.com/
it's work.
I try to fix it next week
Still Doesn't work the authentication goes fine but no info is returned
RépondreSupprimerYou should look at http://stackoverflow.com/questions/21576707/authenticate-to-yammer-in-c-sharp-console-application/25508127#25508127
SupprimerHi,
RépondreSupprimerYour article is fine.But what is the problem on getting information after receiving authentication code. It returns response as "Invalid Client Application". Kindly suggest to solve this problem to proceed further.
Thanks in Advance
Did you find a solution to this problem?
SupprimerHi.. I have a couple of questions... How do you get the "string code" in "AuthCode" method... and is this code completly necessary to that works?
RépondreSupprimerI found the root cause the GetAccessToken() should be with HTTP POST.
RépondreSupprimerthis._userRootObject = this.YammerRequest(AccessTokenService, Method.POST, new
{
code =
_configuration.ClientCode,
client_id =
_configuration.ClientId,
client_secret =
_configuration.ClientSecret,
redirect_uri =
_configuration.RedirectUri,
grant_type =
"authorization_code"
}, false);
Finally, I found the root cause it is because the GetAccessToken() the Http method should be POST.
RépondreSupprimerGetAccessToken() should be HTTP POST
RépondreSupprimerHi Raynald,
RépondreSupprimerThanks for your sharing. :)
Hi,
RépondreSupprimerI was wondering if you are still supporting this? I have been trying to use it, but, I seem to have hit a brick wall and I'm not sure if it is me not understanding Oauth or a bug in the code...
http://stackoverflow.com/questions/31157178/yammer-oauth-application-confusion
Thanks