public/Invoke-FacebookStoryWithPhoto.ps1
function Invoke-FacebookStoryWithPhoto { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$PageId, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Token, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Path ) process{ $ErrorActionPreference = 'Stop' try { $PathExists = Test-Path -Path $Path if ($PathExists) { Start-Sleep -Seconds 10 $Source = Get-Item -Path $Path -ErrorAction Stop # Photos endpoint $Uri = "https://graph.facebook.com/v22.0/$PageId/photos" $Form1 = @{ access_token = $Token published = 'false' source = $Source } $Response1 = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form1 -ErrorAction Stop # Stories endpoint $Uri = "https://graph.facebook.com/v22.0/$PageId/photo_stories" $Form2 = @{ access_token = $Token photo_id = $($Response1.Id) } $Response2 = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form2 -ErrorAction Stop return $response2 } # if } catch { throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # trycatch } # process } # function |