blog.atwork.at

news and infos about microsoft, technology, cloud and more

Access Yammer from an App-Part 2

In part 1 we created a Yammer App and organized all the necessary App data for the authentication. Now let´s develop a .NET sample app for accessing data from the Yammer network.

Communication with Yammer services

Once the authentication is done we can use the Yammer API REST-Services to get data. The URLs all start with https://www.yammer.com/api/v1/... followed by the service methods like https://www.yammer.com/api/v1/messages.json , users.json, groups.json and so on.

See http://developer.yammer.com/restapi/ for all methods. BTW, some of them are still undocumented...

You can implement your own consumption of the REST-services - or use libraries (as we do below).

REST API Limitations

Calls to the Yammer API calls are subject to rate limiting. These are the maximum calls:

  • Autocomplete: 10 requests in 10 seconds.
  • Messages: 10 requests in 30 seconds.
  • Notifications: 10 requests in 30 seconds.
  • All Other Resources: 10 requests in 10 seconds.

If any rate limits are exceeded the service will result in all endpoints returning a status code of 429 (Too Many Requests). Rate limits are per user per app. So keep these limits in mind.

Get help with .NET libraries

There exist some (open source) libraries to simplify the development process.

I personally like using the Yammer.SimpleAPI from codeplex. This is easy to use and offers the most common tasks. The last version is from October 2013.

image

Start something

My sample starts with a new C# project in Visual Studio 2013. I downloaded and extracted the Yammer.SimpleAPI and added it to my new console project and added the reference to it like in the following screenshot.

image

We also added a new class YammerService.cs for the Yammer-specific code.

Start with code and App data

In Program.cs we start with calling the yammerService. The parameters is our data from part 1:

var yammerService = new YammerService(Code, Company, ClientId, ClientSecret);

image

The Yammer service is created with the app data. Please also note to pass the name of the Yammer network (in my app "atwork.at"). If the administrator is member of many networks we have to specify which network shall be used.

We get a token for the user of the yammerService. This token contains the Client-ID and the user token, so all operations are executed as that user. For accessing all groups we need code similar to here:

var myYammer = new YammerClient(myConfig) { AccessToken = this.AdminToken };
var yammerGroups = myYammer.GetGroups();

Now we can loop through the groups of the network and find our group we want to use.

Tip: When you want to post, like, notify people or reply keep in mind that the user has to be member of the specific group where the action takes place! Yammer does not accept f.i. if user "Toni" likes a message in group "Yammer 101" if "Toni" is no (accepted) member of that group. So you have to take care that the user must be a member of that group before trying to access any information in that group.

After having the specific group "Yammer 101" (we need the group ID which here is 2857304) a message can be sent.

MessagesRootObject message = null;
message = myYammer.PostMessage("This is my first Yammer post!", "2857304");

We recommend to see the source code of the https://yammersimpleapi.codeplex.com/ to try the methods provided by this library.

Background work

What happens in the background when consuming the services? Well, the Yammer.SimpleAPI calls the REST-service in the YammerClient-class. The YammerRequest gets the URL of the required method (f.i. .../groups.json), adds the Authorization Token in the HTTP header and adds the object to request.

image

The request return is a JSON object... with a lot of data as result.

image

...which is then deserialized, like the groups here.

image

That´s the magic of the library. I find it comfortable to use the Yammer.SimpleAPI.

Run it

After running the app we should get a new message in the Yammer network. Sent messages appear instantly in the Yammer group. Yammer informs with a small notification about new posts in the group.

image

Click the link or refresh the page in the browser. If everything went well we see the new post.

image

Likes or activities (shown on the right side) can take some seconds to about a minute to be visible.
If different users react the post can become viral. If the actions were made by any other client than the Yammer browser client the source (our app) is shown on the right side near the date and time of the posting.

Conclusion

With the Web APIs Yammer is not a stand alone system. Developers can integrate Yammer services in other systems and communicate with Yammer (and Office 365) users programmatically - which is cool stuff.

Find all Yammer Developer links summarized here:

With that tools have a happy evaluating of the Yammer services!

Comments (3) -

  • Harry

    12/5/2014 11:16:53 PM |

    Nice post. Very helpful.

    One question, I'm building a client app and wondering if it is possible to automate the steps you listed in Part 1 to get the authentication token for the user. So, if I distribute the app to internal users, on app launch, they provide their email/pwd and rest is done through code without showing the App Permission dialog.

    Also, could you please share the YammerService.cs code?

  • Kevin

    5/6/2015 2:39:06 AM |

    Hi... I have a couple of questions... can you show your YammerService class?

    and.... to create my YammerClient, I need the code generated from the App Auth or the access token generated on the json file??

    Sorry, I'm very new on using API's and working with Yammer! Thanks in advance

  • Asif

    7/7/2015 11:21:36 AM |

    I followed your tutorial until now it went really well, but could you please show me the code for yammerService.cs, it shall be thankful to you

  • mgRgp3

    2/12/2018 7:17:30 AM |

    542254 293335I really    delighted  to locate this  internet web site  on bing, just what I was searching  for : D  besides   saved to bookmarks . 535378

Loading