-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGet-YouTubeCommentThread.ps1
45 lines (39 loc) · 1.39 KB
/
Get-YouTubeCommentThread.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function Get-YouTubeCommentThread {
<#
.SYNOPSIS
Retrieves top-level comments from a video, or comments related to a channel.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ParameterSetName = 'VideoId')]
[string] $VideoId,
[Parameter(Mandatory = $true, ParameterSetName = 'ChannelRelated')]
[string] $RelatedToChannelId,
[switch] $Raw,
[Parameter(Mandatory = $false, ParameterSetName = 'VideoId')]
[Parameter(Mandatory = $false, ParameterSetName = 'ChannelRelated')]
[int] $MaxResults = 100,
[Parameter(Mandatory = $false, ParameterSetName = 'VideoId')]
[Parameter(Mandatory = $false, ParameterSetName = 'ChannelRelated')]
[ValidateNotNullOrEmpty()]
[string] $PageToken = ''
)
$Uri = 'https://www.googleapis.com/youtube/v3/commentThreads?part=id,replies,snippet'
switch ($PSCmdlet.ParameterSetName) {
'VideoId' {
$Uri += '&videoId={0}&maxResults={1}' -f $VideoId, $MaxResults
break
}
'ChannelRelated' {
$Uri += '&allThreadsRelatedToChannelId={0}' -f $RelatedToChannelId
break
}
}
if ($PageToken) {
$Uri += '&pageToken={0}' -f $PageToken
}
$Result = Invoke-RestMethod -Uri $Uri -Headers (Get-AccessToken)
$Result.items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.CommentThread') }
if ($PSBoundParameters.ContainsKey('Raw')) { return $Result }
$Result.items
}