Snapchat Script

The following script can be used to generate the refresh token:

$URI = ''
$redirect_uri = ''
echo ""
echo "This script will generate a long lived refresh token for snapchat marketing API."
echo "All information can be found here :"
echo ""
echo "First you need to go to your snap business setting details :"
echo "There you can Create a new OAuth App with App Name : SelligentAudience and Redirect URL : $redirect_uri"
echo "Please provide the clientId and clientSecret listed with this OAuth App."
$adaccount_id = Read-Host -Prompt 'Type in your Ad Account ID'
$client_id = Read-Host -Prompt 'Type in your client ID'
$client_secret = Read-Host -Prompt 'Type in your client secret'
Start-Process "$client_id&redirect_uri=$redirect_uri&response_type=code&scope=snapchat-marketing-api"
echo ""
echo "The browser opens and shows a login page from snapchat : login and then approve the request."
echo "The browser will redirect to $redirect_uri and have a code in the url."
echo ""
$code = Read-Host -Prompt 'Type in the response code'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/x-www-form-urlencoded")
$body = "grant_type=authorization_code&client_id=$client_id&client_secret=$client_secret&code=$code&redirect_uri=$redirect_uri"
$response = Invoke-RestMethod '' -Method 'POST' -Headers $headers -Body $body
$token = $response.refresh_token
echo ""
echo "Provide this data to Marigold!"
echo ""
echo "ad account Id: $adaccount_id"
echo "client Id: $client_id"
echo "client secret: $client_secret"
echo "refresh token: $token"
echo ""
$test = Read-Host -Prompt 'done'