diff --git a/src/facebook/facebook_client.py b/src/facebook/facebook_client.py index ab265bf..cf43038 100644 --- a/src/facebook/facebook_client.py +++ b/src/facebook/facebook_client.py @@ -70,10 +70,12 @@ def get_total_reach( ) -> List[Tuple[datetime, int]]: """ Get statistics on the total reach of new posts. + NOTE: 'page_posts_impressions_unique' is deprecated in v19.0. + Using 'page_impressions_unique' (Total Page Reach) as replacement. """ batches = self._get_all_batches( connection_name="insights", - metric="page_posts_impressions_unique", + metric="page_impressions_unique", period=period.value, since=since, until=until, @@ -91,7 +93,7 @@ def get_organic_reach( """ batches = self._get_all_batches( connection_name="insights", - metric="page_posts_impressions_organic_unique", + metric="page_impressions_organic_unique", period=period.value, since=since, until=until, @@ -127,7 +129,7 @@ def get_new_fan_count( """ batches = self._get_all_batches( connection_name="insights", - metric="page_fan_adds_unique", + metric="page_daily_follows_unique", period=period.value, since=since, until=until, @@ -147,7 +149,12 @@ def _get_all_batches( } params.update(kwargs) page = self._make_graph_api_call(f"{self._page_id}/{connection_name}", params) - result += page["data"] + + if "error" in page: + logger.error(f"Error fetching {connection_name}: {page['error']}") + return result + + result += page.get("data", []) # process next result += self._iterate_over_pages(connection_name, since, until, page, True) # process previous @@ -192,10 +199,16 @@ def _iterate_over_pages( current_page = self._make_graph_api_call( f"{self._page_id}/{connection_name}", args ) + if "error" in current_page: + logger.error( + f"Error in pagination for {connection_name}: {current_page['error']}" + ) + break + if "data" in current_page: result += current_page["data"] else: - logger.error(f"Error in pagination: {current_page}") + logger.warning(f"No data found in pagination response: {current_page}") break return result