如何在 PowerShell 上使用 Curl 命令从 Facebook API 获取数据

How to get data from Facebook API using a Curl Command on PowerShell

我想从 Facebook API 获取一些数据。在他们的网站上提供以下 Linux 命令:

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"

有谁知道等效的 PowerShell 命令是什么? 我想它会像下面这样,但不确定如何添加“-d”参数。

$url = "https://graph.facebook.com/<API_VERSION>/ads_archive"
$output = ".\data\output.json"
Invoke-WebRequest -Uri $url -OutFile $output

我是 PowerShell 的新手,非常感谢任何帮助。

使用-Body选项

document所述:

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