Saturday, 18 June 2016

Retrieve Video Portal, Channels And Videos From Office 365 Using REST Search And List API


Retrieve Video Portal Detail:

First, we will see how we can retrieve the video portal information from Office 365 using SharePoint 2013 REST Search API.

The video portal is a part of the Point Publishing hub site. The site template used to create the portal is POINTPUBLISHINGHUB. The REST search API can be used along with the Web template ID to get the relevant information. Web template property should be used in query parameter to get the channels using search. Template ID should be passed as the Web template value.

The search API will be,
  • https://siteurl/_api/search/query?QueryText='WebTemplate:POINTPUBLISHINGHUB'

The following code snippet shows the JQuery Ajax call to get the video portal information from Office 365 site, using search API:
  1. $.ajax
  2. ({  
  3. "http://siteurl/_api/search/query?QueryText='WebTemplate:POINTPUBLISHINGHUB'",  
  4.     type: "GET",  
  5.     async: false,  
  6.     headers: { "accept""application/json;odata=verbose" },  
  7.     success: function(data){  
  8.         var portalInfo = data.d.query.PrimaryQueryResult.RelevantResults;  
  9.           
  10.             var portalResults = portalInfo.Table.Rows.results;  
  11.         for(var i = 0; i< portalResults.length; i++){  
  12.             console.log("Title : "+portalResults[i].Cells.results[3].Value);  
  13.             console.log("Created By : "+portalResults[i].Cells.results[4].Value);  
  14.             console.log("portal URL : "+portalResults[i].Cells.results[6].Value);  
  15.         }  
  16.         //Similarly other results can be retrieved and displayed  
  17.     },  
  18.     error: function(data){  
  19.     }  
  20. });  

Retrieve Channels:

The channels are separate site collections present on the portal. The site template used to create a channel (site collection) on the video portal is POINTPUBLISHINGTOPIC. Hence, we can use the template ID to query the portal to get the channels available. 

The search API will be,
  • https://siteurl/_api/search/query?QueryText='WebTemplate:POINTPUBLISHINGTOPIC'
Some of the parameters that can be retrieved using the above URL are Channel Name, Created by, Channel URL, etc.

The following code snippet shows the JQuery Ajax call to get the video channels:
  1. $.ajax
  2. ({  
  3.     url: "http://siteurl/_api/search/query?QueryText='WebTemplate:POINTPUBLISHINGTOPIC'",  
  4.     type: "GET",  
  5.     async: false,  
  6.     headers: { "accept""application/json;odata=verbose" },  
  7.     success: function(data){  
  8.         var channelInfo = data.d.query.PrimaryQueryResult.RelevantResults;  
  9.           
  10.         console.log("Available Channels Count : " + channelInfo.RowCount);  
  11.         var channelResults = channelInfo.Table.Rows.results;  
  12.         for(var i = 0; i< channelResults.length; i++){  
  13.             console.log("Title : "+channelResults[i].Cells.results[3].Value);  
  14.             console.log("Created By : "+channelResults[i].Cells.results[4].Value);  
  15.             console.log("Channel URL : "+channelResults[i].Cells.results[6].Value);  
  16.         }  
  17.         //Similarly other results can be retrieved and displayed  
  18.     },  
  19.     error: function(data){  
  20.     }  
  21. });  

Retrieve Videos:

Next, we will see how we can retrieve the videos from the portal in different ways.

1. Using List REST API: From the channels identified, we will access the videos from the respective channels. REST API is used to query SharePoint list items that will be used. To access a video from one single channel, find the following REST List API URL, given below:
  • https://channelurl/_api/web/lists/GetByTitle('Videos')/Items
Channel URL is the channel path name, found from the previous query.

To select necessary properties for the videos, use select parameter and specify the properties. Some of the properties displayed in my example are Title, Author Name, and Video URL. Here, to get the author name, an expanded query needs to be used.

The following code snippet shows the Jquery Ajax call to get the videos present on the specified channel, using List API:
  1. $.ajax
  2. ({  
  3.     url: "http://videoportal_url/_api/web/lists/GetByTitle('Videos')/Items?$select=Title,FileRef,Author/Title&$expand=Author",  
  4.     type: "GET",  
  5.     async: false,  
  6.     headers: { "accept""application/json;odata=verbose" },  
  7.     success: function(data){  
  8.         if(data.d != null && data.d.results.length > 0){  
  9.             var videoResults = data.d.results;  
  10.               
  11.             console.log("Available Videos Count : " + videoResults.length);  
  12.         for(var i = 0; i< videoResults.length; i++){  
  13.             console.log("Title : "+videoResults[i].Title);  
  14.             console.log("Created By : "+videoResults[i].Author.Title);  
  15.             console.log("Video URL : "+videoResults[i].FileRef);  
  16.         }  
  17.     }  
  18.     //Similarly other results can be retrieved and displayed  
  19.     },  
  20.     error: function(data){  
  21.     }  
  22. });   

2. Using Search REST API Query: In the section above, we have seen how we can retrieve the videos from the channels using List REST API. Now, we will see how we can retrieve the videos (same set of information) from the channel using search REST API.

The content type used for video is cloud video. Navigate to SharePoint Video library from channel site and find out the content, type of list, cloud video, and content type. The search API will be,
  • https://siteurl/_api/search/query?QueryText=%27contenttypeid:list_cloudvideo_contenttypeid%27 
The following code snippet shows the Jquery Ajax call to get the videos, present on the specified channel, using the list video content type.
  1. $.ajax
  2. ({  
  3.     url: "http://siteurl/_api/search/query?QueryText='list_cloudvideo_contenttypeid'",  
  4.     type: "GET",  
  5.     async: false,  
  6.     headers: { "accept""application/json;odata=verbose" },  
  7.     success: function(data){  
  8.         var videosInfo = data.d.query.PrimaryQueryResult.RelevantResults;  
  9.           
  10.         console.log("Available Videos Count on Channel : " + videosInfo.RowCount);  
  11.     var videoResults = videosInfo.Table.Rows.results;  
  12.     for(var i = 0; i< videoResults.length; i++){  
  13.         console.log("Title : "+videoResults[i].Cells.results[3].Value);  
  14.         console.log("Created By : "+videoResults[i].Cells.results[4].Value);  
  15.         console.log("Video URL : "+videoResults[i].Cells.results[6].Value);  
  16.     }  
  17.     //Similarly other results can be retrieved and displayed  
  18.     },  
  19.     error: function(data){  
  20.     }  
  21. });   

Thursday, 16 June 2016

Retrieve Channels and Videos from Office 365 Video Portal Using REST Video API

In this post, you will learn how to retrieve the video portal information, video channels and videos of respective channel from the Office 365 sites using REST Video APIs (Newly introduced for Video Portal).

Microsoft has introduced new APIs for working with video portal. The hierarchy of information storage will be,
  • Video portal is present in an Office 365 instance.
  • Video Portal consists of channels.
  • Channels in turn consist of many videos.


Retrieve Video Portal Details:


First we will see how we can retrieve video portal URL of the Office 365 site using REST Video API.

The API used to get the video portal information will be “https://siteurl/_api/VideoService.Discover”. The properties which can be accessed from this operation are, Video Site Page URL, Channel Template URL, Player template URL and Video Site URL.

The following code snippet shows the JQuery Ajax call to get the video portal information from the Office 365 site.
  1. $.ajax
  2. ({  
  3.     url: "/_api/VideoService.Discover",  
  4.     type: "GET",  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data)
  7.     {  
  8.         var videoSiteInfo = data.d;  
  9.         console.log("Video Site Page URL : " + videoSiteInfo.O365VideoPageUrl);  
  10.         console.log("Video Channel URL : " + videoSiteInfo.ChannelUrlTemplate);  
  11.         console.log("Player URL : " + videoSiteInfo.PlayerUrlTemplate);  
  12.         console.log("Video Site URL : " + videoSiteInfo.VideoPortalUrl);          
  13.     },  
  14.     error: function(data){  
  15.     }  
  16. });  


Retrieve Channels:


On the Video portal, you can start creating channels. The channels are used to categorize the videos. Creating channel literally means you are going to create site collections.

To get the channels from the video portal, the video portal URL should be used with REST Video API to pull the information. The REST API URL will be https://videositeurl/_api/VideoService/Channels. Here video site URL is the component which we have identified in the above section.

Next, we will see how we can retrieve information about particular channel. Identify the channel and get the channel id manually or by using the previous operation. The operation will be very similar to the above one. Only difference is Channel id is passed to get the particular channel information.
https://videositeurl/_api/VideoService/Channels('Channel-GUID')

The following code snippet shows the JQuery Ajax call to get the channel details from the Office 365 Video portal.
  1. $.ajax
  2. ({  
  3.     url: "/portals/hub/_api/VideoService/Channels"// Pass Channel id to get particular channel info  
  4.     type: "GET",  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data)
  7.     {  
  8.     var channelInfo = data.d.results[0]; // First Channel  
  9.         console.log("channel Name : " + channelInfo.Title);  
  10.         console.log("channel URL : " + channelInfo.ServerRelativeUrl);  
  11.       // Similarly other properties can be retrieved
  12.     },  
  13.     error: function(data){  
  14.     }  
  15. });  


Retrieve Videos from Channels: 


Now we will see how we can retrieve videos from a particular channel using REST Video API. With the video portal URL and channel ID identified in the above sections, get the channel videos using below API.
https://videositeurl/_api/VideoService/Channels('Channel-GUID')/Videos

The operation will fetch us all the videos from the channel. Using for each, loop through the result set to get the details of each video. The properties which can be viewed are File name, video url, Author details, video download URL, view count, thumbnail url, duration, video uploaded date and channel details. The following code snippet shows the operation in detail.

Now we will see how we can retrieve particular video detail. This is again similar to the above operation. Once you identify the video id, you can pass it using query to SharePoint along with channel id to get more information about single video. The same set of properties will be retrieved here. The REST Video API will be,
https://videositeurl/_api/VideoService/Channels('Channel-GUID')/Videos('Video-GUID') 

The following code snippet shows the JQuery Ajax call to get the video details of a channel from the Office 365 Video portal.
  1. $.ajax
  2. ({  
  3.     url: "/portals/hub/_api/VideoService/Channels('Channel-GUID')/Videos",  
  4.     type: "GET",  
  5.     async: false,  
  6.     headers: { "accept""application/json;odata=verbose" },  
  7.     success: function(data)
  8.     {  
  9.         var videoInfo = data.d.results[0]; // First Video  
  10.         console.log("Video Name : " + videoInfo.FileName);  
  11.         console.log("Video URL : " + videoInfo.Url);  
  12.     // Similarly other properties can be retrieved  
  13.     },  
  14.     error: function(data){  
  15.     }  
  16. });  

Tuesday, 14 June 2016

Retrieve Office 365 Delve Blogs Programmatically using REST API

In this article, you will learn how to get the blogs from Office 365 delve sites on the custom components programmatically using REST API with various filter options.

Query Options :


By default, when user tries to create a blog post from delve user page, the page will be redirected to user's personal site page. All the posts created on delve blog page will be stored in the user’s personal site. i.e., under “/portals/personal/userfirstname/” site.
Some of the queriable fields are content types, file types and file extensions. Only these field values are unique for blogs created on the Office 365 blog site which will not be similar to other items. Some of the unique properties and values are,
  • Content type - The blogs stored on the portal uses story page content type.
  • Secondary File Extensions - The file extension is aspx page but secondary file extension used is PointPub which is unique.
  • File Type - The file type of the blog is PointPub.
We will see how we can query to get the desired results using Search REST API.

Using content type:

First we will find out the content type of story page manually from Office 365 site.
  • From personal site collection, navigate to see all lists folder and then select pages folder. (Or just append “/portals/personal/userfirstname/ppg” to the url and open to see the pages library directly)
  • Go to library settings of Pages library.
  • Click on the Story Page content type. If content types not found, go to advanced settings and allow the content types.
  • From the URL of story page content type, get ctype value. Ctype values shows the content type id of the respective content type. 
Then we need to build the search REST API URL to query the content.

The search REST API using content type will look like below.

Using File Type:

We can also query the blogs using the file type. The file type used for blog is PointPub. The information is stored in JSON format in PointPub files. The file contains the information like Title, SubTitle, Author, Published data, Value, etc. Value contains blog content for each blog.

The search REST API using file type will look like below.

Instead of using file type, you can also use secondary file extension property to filter out the blog data.

We will use Jquery Ajax call to query and get the blog details. In the below code snippet, I have used file type to get all the blog data present on Office 365 site using search API. Similarly other search REST API Url’s can be used to retrieve the blog results.
  1. $.ajax({  
  2.     url: "/_api/search/query?querytext='filetype:PointPub'"// URL can also use content type id to filter the blog data  
  3.     type: "GET",  
  4.     async: false,  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data){  
  7.         var blogInfo = data.d.query.PrimaryQueryResult.RelevantResults;  
  8.         var blogResults = blogInfo.Table.Rows.results;  
  9.         console.log("Title : "+blogResults[0].Cells.results[3]);  
  10.         console.log("Author : "+blogResults[0].Cells.results[4]);  
  11.     },  
  12.     error: function(data){  
  13.     }  
  14. });  
In the above example, title and author values are retrieved for first blog present in the collection. similarly, other properties or blog content can be retrieved from the collection by changingblogResults[i].Cells.results[j] result set.

Monday, 13 June 2016

An Overview of New Office 365 Video Portal


In this post, you will learn about Office 365 video portal. From this portal, users can manage their videos and categorize the videos using channels.


Video Portal:


Microsoft has introduced new video portal for Office 365. Office 365 creates separate site collection for portal (/portals/hub). The point publishing page present on hub site collection will be used to create/upload, view or edit the videos on the portal. The videos on the portal can be categorized using channels. Users can view their own videos or the videos uploaded by other portal users.


Channel:


The channel acts as a category for videos uploaded to the video portal. Users can create new channel from point publishing page.



  • Once channel is created, user can upload videos to the channel.
  • Click on upload button on the top, and select the target channel to upload the video. Set the title and description, then save it.
  • Channel settings helps to modify the settings and information of the video channel.
    • Title or color can be changed for the channel.
    • Permissions can be set for special set of groups.
    • Spotlight – Promoting videos on the channel page.
    • Yammer – Platform to discuss about the channel on yammer.
  • Recycle bin - The component shows all the deleted content on the video portal. Users can restore the deleted content from recycle bin.




Once user go back to the respective channel, they can view the videos they have uploaded to the channel. They can view three tabs, 
  • Trending – Shows videos based on user view count
  • All Videos – Videos from all portal users
  • My Videos – Videos uploaded by logged in user.
Once User clicks on video, video player page will open. Here, Users can play video.

  • Video quality can be changed before playing.
  • Video can be played with full screen mode.
  • Manage section helps user to edit/delete the video.
  • The existing thumbnails of video can be viewed and users can update as new thumbnail for video (Several thumbnails will be generated once a video is uploaded to video porta). Or Users can also upload new thumbnails for any video.
  • Subtitles or captions option will help users to upload subtitles for a video. The subtitles can be uploaded using this option. Subtitles are of .vtt file extensions.
  • Delete option is used to delete the video from portal.