Я пытаюсь запросить в рекламных объявлениях api результаты кампании по дате (например, вчера) и отсортировать по стране.
Нахожу запрос на дату
"https://adsapi.snapchat.com/v1/campaigns/["id"]/stats?granularity=DAY&start_time=["date_start"]&end_time=["date_end"]
и запрос по стране
"https://adsapi.snapchat.com/v1/campaigns/["id"]/stats?granularity=LIFETIME&dimension=GEO&pivots=country"
это мой код, который я просто запрашиваю по стране
r = requests.get("https://adsapi.snapchat.com/v1/organizations/" + organization_id + "/adaccounts", headers = data)
#get all the add accounts
ad_list = json.loads(r.text)
ad_list = ad_list["adaccounts"]
account_list = {}
for obj in ad_list:
test = obj["adaccount"]
account_list[test["name"]] = {}
account_list[test["name"]]["id"] = test["id"]
account_list[test["name"]]["timezone"] = test["timezone"]
#get all the add accounts campaign's
for key in account_list:
r = requests.get("https://adsapi.snapchat.com/v1/adaccounts/" + account_list[key]["id"] + "/campaigns", headers = data)
ad_id = json.loads(r.text)
ad_id = ad_id["campaigns"]
for obj in ad_id:
test = obj["campaign"]
account_list[key][test["name"]] = {}
account_list[key][test["name"]]["type"] = "campaign"
account_list[key][test["name"]]["id"] = test["id"]
#get campaign stats by country
try:
if (req == "1"):
r = requests.get("https://adsapi.snapchat.com/v1/campaigns/" + test["id"] + "/stats?granularity=LIFETIME&dimension=GEO&pivots=country&fields=impressions,swipes,spend", headers = data)
stat = json.loads(r.text)
stat = stat["lifetime_stats"]
stat = stat[0]["lifetime_stat"]
dic = stat["dimension_stats"]
for country in dic:
account_list[key][test["name"]][country["country"]] = {}
for key2 in country:
account_list[key][test["name"]][country["country"]][key2] = country[key2]
except:
continue
Но что бы я ни пытался, я не могу найти способ запросить результат страны между двумя датами. Есть ли решение этой проблемы? Заранее спасибо.