Hey folks. First post here.
I’m building an app that allows users to display their Facebook Page insights in a Dashboard. In order for the dashboard to load faster, I want to build a backend workflow that fetch the insights daily and storing in my own DB.
I have no trouble getting the data from FB Graph API, but the format of the JSON response messes me up. For each page I query, I get a response similar to this:
{
"data": [
{
"name": "page_fans",
"period": "day",
"values": [
{
"value": 2,
"end_time": "2024-06-21T07:00:00+0000"
},
{
"value": 4,
"end_time": "2024-06-22T07:00:00+0000"
},
{
"value": 7,
"end_time": "2024-06-23T07:00:00+0000"
}
],
"title": "Lifetime Total Likes",
"description": "Lifetime: The total number of people who have liked your Page. (Unique Users)",
"id": "<Page ID>/insights/page_fans/day"
},
{
"name": "page_follows",
"period": "day",
"values": [
{
"value": 10,
"end_time": "2024-06-21T07:00:00+0000"
},
{
"value": 12,
"end_time": "2024-06-22T07:00:00+0000"
},
{
"value": 7,
"end_time": "2024-06-23T07:00:00+0000"
}
],
"title": "Lifetime Total Follows",
"description": "Lifetime: The number of followers of your Facebook Page or profile. This is calculated as the number of follows minus the number of unfollows over the lifetime of your Facebook Page or profile. ",
"id": "<Page ID>/insights/page_follows/day"
}
Eventually I need to store the name
, id
, end_time
and value
in my DB. But since value and end_time are nested values of value, I figure I need to build some sort of recursive workflow, that allows me to store each pairs of value
/end_time
and store in my DB with their respective name
/id
. This is where I get lost in the trenches.
Can somebody help me understand what’s the right recursive flow for this?