Friday, December 26, 2014


In the journey of Learning Yammer we have touched various corners of Yammer technology. Yammer is a social network where you can do all  your social activities. You can integrate Yammer with your SharePoint 2013 sites to create community. You can do various things with various options available in Yammer. In this article we will see how to get list of users who are following me on Yammer network. Following and Followers are very important groups in social network. These two groups makes your network on social site. So without these two components your community site is incomplete.

In this article we will see how to get followers of a user. We will achieve this using Yammer REST APIs. Below REST URL returns the followers of a user.

URL: "users/followed_by /[userid].json"

This URL is not mentioned in the Yammer documentation but this gives the expected results. It returns all the users details which are following the mentioned user.
Following script fetches all followers and shows on the screen.

Complete Script:

<script type="text/javascript" data-app-id="[data-app-id]" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script> 
<script type="text/javascript">
var userId = "userid";
var htmlstr = "<div><a href='[URL]'>[NAME]</a></div>";
yam.getLoginStatus(
function (response) {
if (response.authResponse) {
GetFollowing();
}
else {
yam.platform.login(function (response) {
if (!response.authResponse) {
GetFollowing();
}
});
}
});
function GetFollowing(){
yam.platform.request(
 {
 url: "users/followed_by/" + userId +".json"
 , method: "GET"
 , success: function (responseData) {
 ShowHtml(responseData,false);
 }
 , error: function (msg) { 
 alert("Error..." + msg); 
 }
 }
)
}
function ShowHtml(responseData,isNext)
{
var htmlTobind = "";
var last;
for (var j = 0; j < responseData.users.length; j++) {
var html = htmlstr.replace("[NAME]",responseData.users[j].full_name);
html = html.replace("[URL]",responseData.users[j].web_url);

htmlTobind = htmlTobind + html;
}
$("#msgsection").html(htmlTobind);
}
</script>  
<div class="container-fluid" style="margin-top:15px;height:600px;overflow-y:scroll;">
<div id="msgsection" style="width:100%;">
</div>
</div>

You need to provide data app id and user id in above script to run it.

Happy Yamming and SharePoint coding.

0 comments:

Post a Comment