-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNew-YouTubeComment.ps1
39 lines (36 loc) · 1013 Bytes
/
New-YouTubeComment.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
function New-YouTubeComment {
<#
.SYNOPSIS
Creates a new top-level comment on a YouTube video.
.EXAMPLE
New-YouTubeComment -ChannelId UCGpJOTbsdZH_sBxihz6p_wg -VideoId LFWxH-bexNk -Text 'Hello from PowerShell! 👨🏻💻'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $ChannelId,
[Parameter(Mandatory = $true)]
[string] $VideoId,
[Parameter(Mandatory = $true)]
[string] $Text
)
$Uri = 'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet'
$Body = @{
snippet = @{
videoId = $VideoId
channelId = $ChannelId
topLevelComment = @{
snippet = @{
textOriginal = $Text
}
}
}
} | ConvertTo-Json -Depth 5
Write-Verbose -Message $Body
Write-Verbose -Message $Uri
$Headers = (Get-AccessToken) + @{
'Content-Type' = 'application/json'
}
Write-Verbose -Message ($Headers | ConvertTo-Json)
Invoke-RestMethod -Uri $Uri -Headers $Headers -Body $Body -Method Post
}