Patrick Lamber

Patrick Lamber - Mar 7, 2017 - Follow          
Technical consultant and Office Server and Services MVP.

Accessing channels with REST Video API through PowerShell

The post "Accessing channels with REST Video API through PowerShell" is a post of a post series. Find below all posts associated to this post series.
by Patrick Lamber on Mar 7, 2017
Filed under: Governance Office 365 Video Scripts Office 365
Share it:

The REST Video API is used to discover and interact with videos in the Office 365 Video service. You can find the official documentation here. This post is going to show you how you can access channel data through the REST API.

The examples presented in this blog series will use the latest SharePoint Online SDK. You need to download the components to your machine. This post explains how to get the necessary DLLs.

Enumerate your channels

The enumeration of channels can be performed with this simple script. You can use the “Channels” endpoint to achieve this goal.

# your path to the net45 DLLs you downloaded

$pathToCSOM = "H:\Development\net45"
$tenantName = "yourTenantName"
$videoPortalUrl = "https://$($tenantName).sharepoint.com/portals/hub/_api/VideoService/"

# Load the necessary SDK DLLs

[Reflection.Assembly]::LoadFrom("$($pathToCSOM)\Microsoft.SharePoint.Client.dll")
[Reflection.Assembly]::LoadFrom("$($pathToCSOM)\Microsoft.SharePoint.Client.Runtime.dll")

# Authenticate to SharePoint Online

$cred = Get-Credential
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName, $cred.Password);

Function Get-RestContents ($url, $cred) {
    $r = [System.Net.WebRequest]::Create($url);
    $r.Credentials = $cred
    $r.Accept = "application/json;odata=verbose"
    $r.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")

    $res = $r.GetResponse()
    $stream = New-Object System.IO.StreamReader $res.GetResponseStream()
    $results = $stream.ReadToEnd()
    $stream.Dispose()
    return ($results | ConvertFrom-Json).d
}

$url = "$($videoPortalUrl)Channels"
$channels = Get-RestContents $url $cred
$channels.results | Select-Object Id, Title, ServerRelativeUrl
You can get the list of channels to which a user can upload videos. These are the channels to which they have Owner or Editor permissions. This can be achieved with the "CanEditChannels" endpoint.

Get information about a specific channel

The enumaration of channels provides you the channel ID that can be used for other operations. For example you can obtain more information about a channel by using the channel ID and the code below.

# your path to the net45 DLLs you downloaded

$pathToCSOM = "H:\Development\net45"
$tenantName = "yourTenantName"
$videoPortalUrl = "https://$($tenantName).sharepoint.com/portals/hub/_api/VideoService/"

# Load the necessary SDK DLLs

[Reflection.Assembly]::LoadFrom("$($pathToCSOM)\Microsoft.SharePoint.Client.dll")
[Reflection.Assembly]::LoadFrom("$($pathToCSOM)\Microsoft.SharePoint.Client.Runtime.dll")

# Authenticate to SharePoint Online

$cred = Get-Credential
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName, $cred.Password);

Function Get-RestContents ($url, $cred) {
    $r = [System.Net.WebRequest]::Create($url);
    $r.Credentials = $cred
    $r.Accept = "application/json;odata=verbose"
    $r.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")

    $res = $r.GetResponse()
    $stream = New-Object System.IO.StreamReader $res.GetResponseStream()
    $results = $stream.ReadToEnd()
    $stream.Dispose()
    return ($results | ConvertFrom-Json).d
}

$yourChannelId = "yourChannelId"
$url = "$($videoPortalUrl)Channels(guid'$($yourChannelId)')"
$channelInfo = Get-RestContents $url $cred
by Patrick Lamber on Mar 7, 2017
Filed under: Governance Office 365 Video Scripts Office 365
Share it:
The post "Accessing channels with REST Video API through PowerShell" is a post of a post series. Find below all posts associated to this post series.