If somebody like the post and its helpful in your work then, add comments.

Friday, August 1, 2014

Yammer : How to get current logged in user unseen message count

Well this is my first application of Yammer, I was wondering how to start on the application. So, first thing come in my mind that to explore the Yammer,

What is yammer?

How can we use it?

What are the entities in yammer, which we can use or integrate in our application. etc

So, logged in Yammer, created network added the people. So, now when all thing are up then for just creating a sample application a scenario occurs in my mind “current logged in user unseen message count”. How to start on the, where to deploy that????

I added one more Technology my FAV one, SharePoint. Final scenario showing  current logged in user unseen message count in SharePoint online. Created a trial account in that and create on page. First I tried with yammer default feed JS code. It works find ….OK.

So, for custom development I looked on Google and found the wonderful description on yammer API. How to consume in various domains, how add in various platforms. Link is below

https://developer.yammer.com/connect/

To get current logged in user unseen message count

<h1><b>Yammer</b></h1> 
    <h3 > Unseeen Messages</h3><div id="numberOfMessages"></div>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" data-app-id="[Your App ID]" src="https://assets.yammer.com/assets/platform_js_sdk.js"></script>
 

    <span id="yammer-login"></span>
   
    <script type="text/javascript" >
        yam.getLoginStatus(
      function(response) {
        if (response.authResponse) {
              console.log("logged in");            
               yam.platform.request({
                url: "networks/current.json",
                method: "GET",       
                beforeSend: function (req) { //print message response information to the console
                    yam.platform.setAuthToken(response.access_token);
                } ,
               
                success: function (user) { //print message response information to the console
                    document.getElementById('numberOfMessages').innerHTML= user[0].unseen_message_count;
                },
                error: function (user) {
                  alert("There was an error with the request.");
                }
              });

        }     
      }
    );
    </script>

but before adding the above code we have to create on app in yammer

image

image

image

remember this redirect URL should be match with your domain and JavaScript origin will be the URL of page where the JS or JS is rendering.

Click Save

image

This big bold highlighted one is the key point where I stuck an have goggling for like 2 days Smile

image

image

5 comments:

  1. Hi Bharat,

    Do you have any issue with:
    yam.platform.setAuthToken(response.access_token);
    I think it should be:
    yam.platform.setAuthToken(response.access_token.token);
    Right?

    Actuarially, without this setAuthToken, it should still work. according to https://developer.yammer.com/yammer-sdks/#javascript-sdk

    It mentions that:

    Once I have ran this "yam.platform.getLoginStatus(callback, [forceRefresh])", subsequent calls to yam.platform.request will automatically use the token returned by this call.

    And yes, no matter I have this line of code or not, the yammer App works fine with my personal yammer account.
    But, if I use my company's account, it will have token issue, not matter I have your setAuthToken code or not.

    Do you have this issue? My company uses sharepoint as well, so I think you may have the same issue.

    Thanks,
    Peter

    ReplyDelete
    Replies
    1. Yes, There is issue in getting the unread count of the messages. In yammer its given that it will work. But I find out that we have to add token before sending the request explicitly.

      Bharat Sukhwal

      Delete
    2. anyway, I only use login+ get current user + get current user's group. these functions work fine with me without the token setting.

      However, I got error if I user my company's account. But it works fine with my previous company's account. I think that because my current company uses a lot of MS service. Do you have this issue?

      Delete
    3. Well are you using the single sign on of the Yammer ?

      Delete