Enhancing the Yammer Search Results and Messages Samples and Deserialization
Just as kind of strange coincidence, I was in working on some Yammer message JSON goo and realized that there were actually a couple of other important data elements that comes down in the JSON payload when you get a collection of messages from REST. That includes both querying for messages directly, as well as getting a collection back in search results. In addition to the messages themselves, there's also some info that can be used with the realtime API, as well as what it calls "references". The beauty of the references content is that it includes information about each user referenced in the collection of messages that are returned. I missed this the first time around, just one of the dangers at trying to stare at about 4k of JSON and hoping to extract everything useful out of it. Mucho love here to Fiddler and it's JSON parser for snapping me out of it. :-)
If you read the blog post on integrating search results here: https://blogs.technet.com/b/speschka/archive/2014/03/11/integrating-yammer-and-sharepoint-2013-search-results.aspx - you saw that when I got a list of search results back, I actually made a second call back to Yammer for each one to get information about the user associated with the message. By pulling in the references information I no longer need to make those additional round trips now.
So there are two things I wanted to briefly touch on here. First, I've updated the definition of the YammerMessages class; the JSON returned from Yammer is serialized into this class. I've now added additional properties into which the realtime and references information is hydrated when you call GetInstanceFromJSON. I've attached the updated class to this posting so you can download it and use it in your projects and then you will "automatically" get this new goodness. The second thing is I rewrote the section of code in the search WebAPI service I had so that it uses that References collection now instead of calling back to Yammer. I'm just going to paste in here the chunk of code from that solution that has changed; if you are going to build on that example I linked to above just plug in this new code:
foreach (YammerMessage ym in ysr.Messages.Messages)
{
#region used this method to get the user info by querying Yammer again
////get the Yammer User that posted each message so we can pull in
////their picture url
//string userUrl = oneUserUrl.Replace("[:id]", ym.SenderID);
//response = YammerREST.MakeGetRequest(userUrl, accessToken);
//YammerUser yu = YammerUser.GetInstanceFromJson(response);
#endregion
var yUser = from YammerMessagesReferences yr in ysr.Messages.References
where ym.SenderID == yr.ID
select yr;
YammerMessagesReferences ymr = yUser.First<YammerMessagesReferences>();
//add a new search results
//finds.Add(new SearchResult(yu.FullName, yu.WebUrl, yu.FirstName, ym.MessageContent.RichText, yu.PhotoUrl, DateTime.Parse(ym.CreatedAt), ym.WebUrl));
finds.Add(new SearchResult(ymr.FullName, ymr.WebUrl, ymr.UserName, ym.MessageContent.RichText, ymr.MugshotUrl, DateTime.Parse(ym.CreatedAt), ym.WebUrl));
iCount += 1;
if (iCount == 3)
break;
}
Comments
- Anonymous
January 01, 2003
The comment has been removed - Anonymous
January 01, 2003
thanks - Anonymous
September 18, 2014
The comment has been removed - Anonymous
October 15, 2014
The comment has been removed - Anonymous
October 15, 2014
Link m88 : http://www.m88no.com/Main/Home.aspx?affiliateId=99156 - Anonymous
December 16, 2014
The comment has been removed - Anonymous
January 08, 2015
m88 : http://m88en.com
M88.com offer online sports games Asia, Sports Betting Asia, Sports Betting Sites Asia.
m88asia : http://m88en.net
Link to M88BET phone: m88en.com. – Register and Open Betting Account and Membership M88BET.
m88bet : http://www.linkm88vip.com
MANSION88 the house is one of the largest and most prestigious. Appeared quite early in the Asian market, the so-MANSION88 currently attracts more players.
link m88 : http://m88wiki.com
Home the M88 is the official sponsor of the football club in the Premier League
Wish you happy with the new M88
m88 casino online : http://m88free.com
Modern Thai restaurant combines outstanding traditional cuisine and a subtle modern decor with a warm welcoming ambience. Thai Restaurants in Brisbane :http://www.watersidethainoodles.com.au , traveller reviews of Brisbane Thai restaurants and search by price, location, and more..