httpwebrequest r = webrequest.create(url) as httpwebrequest;...

37

Upload: lyndsey-brisby

Post on 15-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using
Page 2: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Integrating Yammer and Microsoft SharePoint Using .NETRichard diZerega

OFC-B254

Page 3: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Session Objectives And TakeawaysSession Objective(s): Learn the common APIs used in custom Yammer applicationsIllustrate how to work with Yammer data in .NET codeDetail challenges and lessons learned from integrating Yammer into technology solutions

Key TakeawaysYammer offers a diverse set of APIs that follow industry standards such as OData and RESTIntegrating Yammer into new and existing solutions can be achieved easily with .NETSocial integration with Yammer can provide value to almost any application

Page 4: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

AgendaYammer APIsWhat are they, where are they, and how do they size up against SharePoint Social APIs

Yammer Apps and AuthenticationHow do I register an application and authenticate to call the Yammer APIs

Yammer and .NETHow do I build against Yammer APIs in .NET

Yammer integration with SharePointUnderstand how to use Yammer data in SharePoint and SharePoint data in Yammer

Going Further with Yammer DevelopmentAdditional lessons learned for from building highly interactive applications with Yammer

Page 5: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer APIs

Page 6: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer APIsYammer developer documentation available onlineAll supported APIs documented at developer.yammer.comOther APIs exist, but be careful as they subject to change without noticeYammer Developer Network also good resource for additional documentation

The REST endpoints are easiest APIs for .NETThat’s where most data access occurs today, and where investments are being made for the futureAll REST APIs support json data, but many also support xml (think LINQ to XML)If you are doing client-side development, then you should consider Yammer’s JavaScript SDKFor more advanced data scenarios Yammer also has a Graph API

Page 7: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

What’s REST APIs are Available?

Groups Networks

Autocomplete

Notifications

Suggestions

Invitations

Real-timeOpen Graph

Messages Attachments

Post

Reply Like/Unlike Mention

Tag Search Profiles

Follow Unfollow Relationships

Page 8: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Demo

REST APIs

Page 9: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer Apps and Authentication

Page 10: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer App BasicsMake sure you register your Yammer app firstRegister apps at https://www.yammer.com/client_applicationsYou will get a Client ID and Client SecretThe App will only work in your home network until it is marked global

Be aware of request throttlingThere are limits to how frequently you can make requests to the REST API. See http://developer.yammer.com/restapi/ for full throttling details

Once you have an access token, it’s good foreverNo expiration, but can be revoked by userAccess token is app-specific and has as much rights as the person it is associated withAccess token must be present in the header of Yammer REST API callsSome APIs are only available to network administrators

Page 11: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer AuthenticationYammer JavaScript SDKTurns any div element into a login button (yam.connect.loginButton)OAuth process implemented through a pop-up, which can be problematic with IE Security Zones

Manual Authentication1. App redirects to https://www.yammer.com/dialog/oauth with client id and redirect url2. Yammer will either use the browsers authentication token or prompt the user to login3. Yammer will prompt the user to allow the app access to Yammer information (if not previously

allowed)4. Yammer will return a context code to the redirect url passed in step 15. App performs a GET against https://www.yammer.com/oauth2/access_token.json with the

client id, client secret, and code Yammer provided in step 46. Yammer returns an access token to the app7. App uses access token to make all additional API calls

Fully documented at https://developer.yammer.com/authentication/

Page 12: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer authentication flow1) App redirects to

Yammer’s OAuth REST endpoint

2) Yammer sends user to login page***

3) User logs into Yammer4) Yammer prompts user

to authorize the app***5) Yammer returns app a

context code6) App uses context code

to get access token from Yammer

7) App uses access token to query Yammer

Page 13: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer and .NET

Page 14: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer APIs with .NETHow do you work with Yammer APIs from .NET?1. You need to make GET and POST HTTP requests2. You need to have an access token and provide it in the header of requests3. Understand that when you make a REST API call, you will likely be get back JSON

There are strategies for each of these1. Make GET and POST HTTP requests with HttpWebRequest/HttpWebResponse2. Set the access token in the header with

HttpWebRequest.Headers.Add("Authorization", "Bearer" + " " + accessToken);3. Several libraries for serializing/deserializing JSON in .NET including Newtonsoft.Json

(JSON.NET) and System.Runtime.Serialization.Json

Page 15: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer GET from .NET

HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest;r.Headers.Add("Authorization", "Bearer" + " " + accessToken);using (HttpWebResponse resp = r.GetResponse() as HttpWebResponse){ Encoding e = System.Text.Encoding.GetEncoding("utf-8"); StreamReader s = new StreamReader(resp.GetResponseStream(), e); string json = s.ReadToEnd();

Page 16: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer POST from .NETSetCookies(); //get the session and yamtrack cookieHttpWebRequest r = WebRequest.Create(url) as HttpWebRequest;r.Headers.Add("Authorization", "Bearer" + " " + accessToken);r.Method = "POST";r.CookieContainer = cookieContainer;

//set the post data and content typebyte[] postByte = Encoding.UTF8.GetBytes(postData);r.ContentLength = postByte.Length;r.ContentType = String.IsNullOrEmpty(contentType) ? "application/x-www-form-urlencoded" : contentType;

//write the stream and get responseStream postStream = r.GetRequestStream();postStream.Write(postByte, 0, postByte.Length);postStream.Close();using (HttpWebResponse resp = r.GetResponse() as HttpWebResponse){ postStream = resp.GetResponseStream(); StreamReader postReader = new StreamReader(postStream); var json = postReader.ReadToEnd();

Page 17: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

.NET Utilities for YammerSeveral utilities available onlineYammerUtil.cs that I use is available through the Yammer Export Processor post on my blog. This is a complete Yammer solution that performs a Yammer export and processes the messages for additional details using REST and throttling http://blogs.msdn.com/b/richard_dizeregas_blog/archive/2014/04/09/yammer-analytics-with-excel-and-power-bi.aspx

My SPC session on Yammer Data Mining includes code downloads for additional .NET utilities, including real-time APIs in a .NET console application http://channel9.msdn.com/Events/SharePoint-Conference/2014/SPC3991

Steve Peschka has blogged several utilities for working with Yammer in .NET that are available on his blog, including simple MakeGetRequest(url, token) and MakePostRequest(formData, url, token) methods for the REST APIs http://blogs.technet.com/b/speschka/archive/2013/10/05/using-the-yammer-api-in-a-net-client-application.aspx

Page 18: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer/SharePoint Integration

Page 19: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Scenario 1 – Yammer data in SharePointScenarioCustomer uses Yammer for IdeationThread root is a challenge that employees post ideas toTop ideas are identifies by the number of “Likes” received by employeesCustomer wants an application to aggregate the Yammer Ideation dataCustomer wants the app accessible in their sales portal and from mobile devices

SolutionWrite an app for SharePoint that queries the “Ideation” group in YammerAggregate/Sort messages within a challenge thread by number of LikesCreate a provider-hosted app part to host the app in SharePointThe app should be accessible from SharePoint AND mobile devices since it’s just ASP.NET

Page 20: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Demo

Yammer Data in SharePoint

Page 21: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Scenario 2 – SharePoint data in YammerScenarioCustomer has daily sales contests and wants to socialize daily winners in YammerSales metrics are stored in SharePoint Lists and other LOB solutions

SolutionCreate a SharePoint app to read the sales metricsSchedule the app to run daily as a timer jobAggregate the sales totals for each dayWrite a message in Yammer recognizing the top 3 sellers

Page 22: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Demo

SharePoint Data in Yammer

Page 23: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Going Further

Page 24: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

ThrottlingThrottle by pagingMay Yammer APIs return in batches of 50, especially calls that could return large amounts of data such as a popular users followers or the members of a groupPaged APIs will return a more_available value indicating if more are available (total counts are typically available too)

Throttle by call frequencyYammer throttles by call frequency based on the type of query…throws 429 errors when exceeded:

Autocomplete: 10 requests in 10 secondsMessages: 10 requests in 30 secondsNotifications: 10 requests in 30 secondsAll Other Resources: 10 requests in 10 seconds

Consider a calling queue for bulk operations (ex: ETL)

Page 25: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Demo

Throttling

Page 26: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Yammer’s Real-time APIUses the Bayeux Protocol of longpoll requestsClient makes a json request to Yammer with a long timeout (ex: 30 seconds)At any time, Yammer could respond with a real-time responseAt the least, Yammer will respond before the timeout indicating no messagesClient immediately makes new json request when it receives a response from Yammer

Steps to implementDiscover – determine the channel id of the feed to connect withInitialize – call into https://www.yammer.com/api/v1/realtime for realtime endpointHandshake – use the realtime endpoint to perform handshake with access tokenSubscribe – subscribe to the feeds you want in realtimeConnect – Perform long-polling calls to Yammer for realtime messages

Fully documented at https://developer.yammer.com/realtime/

Page 27: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Demo

Yammer’s Real-time API

Page 28: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Mention #yamapps on itpronetwork

Page 29: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Session Objectives And TakeawaysSession Objective(s): Learn the common APIs used in custom Yammer applications Illustrate how to work with Yammer data in .NET code Detail challenges and lessons learned from integrating Yammer into technology

solutions

Key Takeaways Yammer offers a diverse set of APIs that follow industry standards such as OData and

REST Integrating Yammer into new and existing solutions can be achieved easily with .NET Social integration with Yammer can provide value to almost any application

Page 30: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

OFC-B220 Stop, Collaborate, and Listen - Monday @1:15OFC-B254 Integrating Yammer and Microsoft SharePoint Using .NET - Monday @1:15OFC-B262  Microsoft's Roadmap for Enterprise Social - Monday @4:45OFC-B274 Implementing Microsoft SharePoint 2013 Hybrid for Search, Business Connectivity Services, Microsoft OneDrive for Business and Yammer - Tuesday @1:30OFC-B240 Introducing Codename "Oslo" and the Office Graph - Tuesday @5:00OFC-B241 Integrating SharePoint Portals with Social, Search, and Video - Wednesday @8:30OFC-B235 How to Become a Yammer Power User in 75 Minutes - Wednesday @1:30OFC-B221 Best Practices for Breaking Down Organizational Barriers Using Yammer - Thursday @8:30

Related Enterprise Social Sessions

SOCIALIZE swing by the Work Together booth and Asks the Experts!

Page 32: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Microsoft Enterprise Social resources todaySites, Blogs & Twitter

Enterprise Social Customer Success - Yammer Success Center - EnterpriseSocial.com - The Responsive Org

Admin & IT - Developers - Yammer App Directory - Office Store - Yammer Ignite Blogs: Yammer Office 365 Twitter: @Yammer @Office365

Research/Whitepaper Gartner: Magic Quadrant for Social Software in the Workplace - Evolution of the networked

enterprise: McKinsey Global Survey results - Yammer’s 2013 Business Value Survey Results - The Rise Of Enterprise Social Networks

Press How Red Robin Transformed Its Business With Yammer -

How Teach for America gets the most out of Yammer on a shoestring budget - HK firm creates idea melting pot for 4,000 employees - LexisNexis found that employees who use Yammer are way happier - Switching to Yammer let this company slash helpdesk calls and save $1.5 million a year - How Microsoft got its own employees to use Yammer

Videos Move Faster Together - Transform the Way You Work with Yammer

And a lot more to come!

#WorkLikeANetwork

Page 33: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using
Page 34: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Resources

Learning

Microsoft Certification & Training Resources

www.microsoft.com/learning

msdn

Resources for Developers

http://microsoft.com/msdn

TechNet

Resources for IT Professionals

http://microsoft.com/technet

Sessions on Demand

http://channel9.msdn.com/Events/TechEd

Page 35: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Complete an evaluation and enter to win!

Page 36: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

Evaluate this session

Scan this QR code to evaluate this session.

Page 37: HttpWebRequest r = WebRequest.Create(url) as HttpWebRequest; r.Headers.Add("Authorization", "Bearer" + " " + accessToken); using

© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.