Thursday, July 17, 2014


In journey of Yammer - SharePoint integration till now we have seen various available approaches. We have taken some real time scenarios and saw how we can implement them. We saw how to use Yammer web part's various options and create community in  SharePoint. After web part we saw Yammer Embed integration options.

Yammer  web part and embeds are just ready made  solution and we don't have controls to modify them.  We cannot control what data needs to be display, how it should get displayed. But in case of Yammer REST API we have better control on data display and behave of application. You can do implementation as per the requirement. With these REST endpoint you can fetch and submit information to Yammer. These end points supports JSON and xml.

Following Yammer objects have REST endpoints: Messages, Groups, Users, Relationship, Notification, Suggestions, Subscription, Autocomplete, Invitation, Search and Networks.

Now lets see how  to write code for Yammer REST API. This is simple, you just need to know REST and JavaScript. The SDK has been provided by Yammer which makes life more easier for developers. Just use the api as it is and start coding against Yammer. In Apr/May Yammer Team has published new REST libraries due to security reasons. So we will discuss here only on new way of writing code.

Following code snippets is standard and I  will explain each line for you.

1.     <script type="text/javascript" data-app-id="YOUR-APP-CLIENT-ID" src="https://assets.yammer.com/assets/platform_js_sdk.js"></script>       
2.      yam.getLoginStatus(
3.             function (response) {
4.                if (response.authResponse) {
5.                        //WRITE CODE TO CALL REST ENDPOINTS
6.                }
7.                        else {
8.                    yam.platform.login(function (response) {
9.                        if (!response.authResponse) {
10.                                    //WRITE CODE TO CALL REST ENDPOINTS
11.                        }
12.                   });
13.               }
14.            });

Lets see every code line in detail:

Line 1. This line loads the required sdk through this library. This is important library and must be included. You also need to provide data-app-id.
Line 2. Next line gets the Yammer login status of user using method yam.getLoginStatus which returns login status.
Line 3. This line has function which gets called in response to getLoginStatus call.
Line 4. This line has if loop which checks auth response is true or not if it is true then it execute next line means control comes in if loop that means user has already logged in. But if auth response is false then it goes to else block.
Line 5. At line 5 start writing your code and calls to REST endpoints.
Line 7. Else block gets executed when user is not logged in.
Line 8. At this line yam.platform.login opens pop up for user to login to Yammer.
Line 10. Write the logic and Yammer REST endpoints calls same as at line 5. This if block gets executed when user gets logged in successfully.

So in this way you can start Yammer REST API coding. Is it simple? Yes it is simplest. With these APIs you can write powerful components for integration with SharePoint. We will see each endpoint in detail.

Happy SharePoint coding.



0 comments:

Post a Comment