我可以使用Postman API访问广告,并使用Postman应用程序中的'[Code'选项获得了python请求代码。但是time_increment在某些情况下有效。当time_increment子句起作用时,我收到了JSON响应,无法将其转换为熊猫数据框。
我的代码如下:
import requests
url = "https://graph.facebook.com/v5.0/act_<------id------>/insights?fields=campaign_id,campaign_name,clicks,unique_clicks,reach,spend,impressions,cost_per_unique_click,purchase_roas,website_purchase_roas&time_range={\"since\":\"2019-12-01\",\"until\":\"2019-12-07\"}&time_increment(1)&limit(200)"
payload = {}
headers = {
'Authorization': 'Bearer <access_token>'
}
response = requests.request("GET", url, headers=headers, data = payload)
res = response.json()
print(res)
[当我运行上述代码时,我没有得到所需的列,例如campaign_id,campaign_name等。而且time_increment子句都不起作用。
高度赞赏任何解决方案。请!上周的大部分时间我都被困在这里。
我的输出是:
{
"data": [
{
"clicks": "45547",
"unique_clicks": "63257",
"reach": "4269850",
"spend": "69403.83",
"impressions": "8525031",
"cost_per_unique_click": "13.57562",
"purchase_roas": [
{
"action_type": "xxxxxxxxx",
"value": "1.571284"
}
],
"website_purchase_roas": [
{
"action_type": "yyyyyy.zzzzzzz",
"value": "4.587928"
}
],
"date_start": "2019-12-01",
"date_stop": "2019-12-07"
}
],
"paging": {
"cursors": {
"before": "MAZDZD",
"after": "MAZDZD"
}
}
}
import requests
payload = {}
headers = {
'Authorization': 'Bearer <access_token>'
}
r = requests.get(
"https://graph.facebook.com/v5.0/act_<------id------>/insights?fields=campaign_id,campaign_name,clicks,unique_clicks,reach,spend,impressions,cost_per_unique_click,purchase_roas,website_purchase_roas&time_range={\"since\":\"2019-12-01\",\"until\":\"2019-12-07\"}&time_increment(1)&limit(200)", headers=headers, json=payload).json()
print(r)