我能够使用以下 curl 让它工作
curl --cert ./<PI2 CERTIFICATE FILE>.p12 --pass <PI2 CERTIFICATE PASSWORD> -H "Authorization: orgId=xxx" -H "Content-Type: application/json" -X POST -d ' {"startTime": "2017-04-06", "endTime": "2017-04-06", "granularity": 2, "selector": {"orderBy":[{"field":"localSpend","sortOrder":"DESCENDING"}], "fields": ["localSpend"], "pagination": { "offset": 0, "limit": 1000 } }, "groupBy": ["COUNTRY_CODE"], "returnRowTotals": false, "returnRecordsWithNoMetrics": false }' "https://api.searchads.apple.com/api/v1/reports/campaigns/campaign name/searchterms"
您可以按照此处提到的步骤获取 p12 证书
https://developer.apple.com/library/content/documentation/General/Conceptual/AppStoreSearchAdsAPIReference/API_Overview.html#//apple_ref/doc/uid/TP40017495-CH7- SW8
如果您在 python 中使用请求进行 post 调用,您可能需要做一些额外的工作,因为我没有找到任何将 p12 证书和密码作为输入的参数。使用 openssl 创建 crt 文件和 pem
openssl pkcs12 -in Apple_Certificate.p12 -out file.crt.pem -clcerts -nokeys
openssl pkcs12 -in Apple_Certificate.p12 -out file.key.pem -nocerts -nodes
并使用以下代码
headers = {
'Authorization': 'orgId=<ORG_ID>',
'Content-Type': 'application/json',
}
data = ' {"startTime": "%s",
"endTime": "%s",
"granularity": 2, ' \
'"selector": {"orderBy":[{"field":"localSpend","sortOrder":"DESCENDING"}], ' \
'"fields": ["localSpend"], "pagination": { "offset": 0, "limit": 1000 } }, ' \
'"groupBy": ["COUNTRY_CODE"], "returnRowTotals": false, "returnRecordsWithNoMetrics": false }' % (date_report, date_report)
url = 'https://api.searchads.apple.com/api/v1/reports/campaigns/%s/searchterms' % (your_campaign_id)
r = requests.post(url, headers=headers, data=data,
cert=('<path to crt file>',
'<path to key file>'))