public/New-SocialMediaLongLivedToken.ps1
function New-SocialMediaLongLivedToken { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$AppId, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$AppSecret, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$ExchangeToken, [Parameter(Mandatory=$true)] [ValidateSet('facebook')] [string]$Platform ) process { $ErrorActionPreference = 'Stop' try { if ($Platform -eq 'facebook') { $Body = @{ grant_type = "fb_exchange_token" client_id = $AppId client_secret = $AppSecret fb_exchange_token = $ExchangeToken } $Uri = "https://graph.facebook.com/v22.0/oauth/access_token" $Response = Invoke-RestMethod -Uri $Uri -Method Get -Body $Body $LongLivedToken = $($Response.access_token) } # if return $LongLivedToken } catch { "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # try catch } # process } # functon |