Tuesday, 23 September 2014

Yammer application (javascript application)

No matter you want to create a web page to get data from yammer or you want to load yammer's data to your mobile application or just embed some yammer's data in a small section of you web page or some place. All that requirements require a Yammer application.


1. you should first create a yammer application from your yammer account, which means you at least have a yammer account.



    then you get this page :


2. then visit api website of yammer: https://developer.yammer.com/yammer-sdks/#javascript-sdk. follow the instruction. or just follow the instruction here which is much easier.

3. create a html file and put this into your html section:

<script type="text/javascript" data-app-id="YOUR-APP-CLIENT-ID" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
the YOUR-APP-CLIENT-ID is the client id shows on the last picture above, you should put it here. that will identify your application. Then Yammer can approve all request from your website. (your application must runs on a public website, or localhost is not possible to send request to Yammer, Yammer will abandon your requests. )

4. Add a login button in your application. Of cause to make a testing application , this is not necessary.  You can login on yammer website and browser will cache your login status, then open your application after that. But if you want a login button, please put below code into your html file.
<span id="yammer-login"></span>
<script> yam.connect.loginButton('#yammer-login', function (resp) { if (resp.authResponse) { document.getElementById('yammer-login').innerHTML = 'Welcome to Yammer!'; } }); </script>
5. let's query some data from yammer. Use below code and just put into javescript section of your html file. Please use this code, do not use the sample code of yammer api. you will know why later.

To check the result, you should use chrome or firefox to see the console log. it will show all of users of your organisation.

  function(response) {
    if (response.authResponse) {
      console.log("logged in");
        url: "users.json",     //this is one of many REST endpoints that are available
        method: "GET",
        data: {    
        success: function (user) { //print message response information to the console
          alert("The request was successful.");
        error: function (user) {
          alert("There was an error with the request.");
    else {
      alert("not logged in")

then you will have no problem.

I got some error, when I try to use another account from another organisation to access this application , even not able to login.

The problem is that you only deploy this application by one user for one specific organisation. and it is not able to be used by another organisation. (remember the client ID? that is only for your current organisation)

No comments:

Post a comment