I want to get some data from Facebook API. On their website the provide the following Linux command:
curl -G \
-d "search_terms='california'" \
-d "ad_type=POLITICAL_AND_ISSUE_ADS" \
-d "ad_reached_countries=['US']" \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/ads_archive"
Does anyone know what will be the equivalent PowerShell command? I suppose that it will be something like the below, but not sure how to add the "-d" parameters.
$url = "https://graph.facebook.com/<API_VERSION>/ads_archive"
$output = ".\data\output.json"
Invoke-WebRequest -Uri $url -OutFile $output
I am new to PowerShell so any help will be greatly appreciated.
use -Body
option
as document describes:
When the input is a GET request and the body is an IDictionary (typically, a hash table), the body is added to the URI as query parameters. For other request types (such as POST), the body is set as the value of the request body in the standard name=value format.
$params = @{
"search_terms" = "'california'";
"ad_type" = "POLITICAL_AND_ISSUE_ADS";
"ad_reached_countries" = "['US']";
"access_token" = "<ACCESS_TOKEN>"
}
$url="https://graph.facebook.com/<API_VERSION>/ads_archive"
Invoke-WebRequest -Method Get -Uri $url -Body $params