Hoping the best for everyone today.
Context:
Currently I use Facebook Analytics to pull data from my specific Facebook pages about my visitors and their posts. This data is then entered into a monthly report manually. I'm building a python script to pull this data and format a .csv for me.
Expected Outcome:
For example here, I've entered August 1 - 31 into Facebook Analytics and I see the demographic breakdown for my page visitors for this window of time.
Facebook Analytics Web Interface Example
Male: 5.26k Female: 679
I would expect my code to pull these numbers, or at least something very similar.
What I'm Trying:
This is the python facebook.get_object request I'm making to the Facebook Graph API -
pageDemographics = (graph.get_object(page["pageId"] + "/insights/page_fans_gender_age?date_preset=last_month"))
print(pageDemographics)
This results in a page of data like so..
Essentially a 31 item list of dictionaries, where each dictionary represents a day and a demographic breakdown {gender, age bracket : amount of people}, {gender, age bracket : amount of people}, etc.
Every day in this list of dictionaries seems to have different values, sometimes higher and sometimes lower than the day before. Moreover, for example, when all of the males for one given day are added up they can vastly out number the number of males found on the Facebook Analytics web interface for the time frame of August 1 - 31. For example, August 31st males, according to my code, is 97,110 compared to the web interface's 5,260.
I've tried to run this call with a "period" added in to aggregate the data into a month like this.
pageDemographics = (graph.get_object(page["pageId"] + "/insights/page_fans_gender_age?date_preset=last_month&period=month"))
print(pageDemographics)
oddly, this returns...
{"data": [], "paging": {"previous": "https://graph.facebook.com/v3.3/pageid/insights?access_token=token&metric=page_fans_gender_age&period=month&date_preset=last_month&since=1561964400&until=1564642800", "next": "https://graph.facebook.com/v3.3/pageid/insights?access_token=token&metric=page_fans_gender_age&period=month&date_preset=last_month&since=1567321200&until=1569999600"}}
*note, page id's and tokens have been redacted
What to do Next:
I've been trying to figure out how to better form my query using facebook's api documentation on insights: https://developers.facebook.com/docs/graph-api/reference/v4.0/insights
I'd really appreciate some help better forming these queries to get the data I'm after. OR at least an explanation of what's wrong with my code.
Cheers & let's keep learning,