Snapchat Script

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

$URI = 'https://accounts.snapchat.com/login/oauth2'
$redirect_uri = 'https://www.snapchat.com'
echo ""
echo "This script will generate a long lived refresh token for snapchat marketing API."
echo "All information can be found here : https://marketingapi.snapchat.com/docs/#authentication"
echo ""
echo "First you need to go to your snap business setting details : https://business.snapchat.com/"
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 "https://accounts.snapchat.com/login/oauth2/authorize?client_id=$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 'https://accounts.snapchat.com/login/oauth2/access_token' -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'