/*
* Zernio API
*
* API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api Versioning and deprecation: all endpoints are versioned in the URL path (current version: /v1). Breaking changes only ship in a new path version; existing versions keep working. Deprecated operations are marked 'deprecated: true' in this spec and announced in the changelog (https://zernio.com/changelog) before removal. Errors: every 4xx/5xx response is application/json with a machine-readable 'code' and a human-readable 'error' message (see the ErrorResponse schema). Request ids: responses carry an X-Request-Id header with the id we log the request under. Quote it when reporting a problem. A valid x-request-id you send is reused as that id.
*
* The version of the OpenAPI document: 1.575.1
* Contact: support@zernio.com
* Generated by: https://openapi-generator.tech
*/
use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
/// struct for typed errors of method [`cancel_tracking_window`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CancelTrackingWindowError {
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_analytics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAnalyticsError {
Status400(models::GetAnalytics400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status404(models::InlineObject2),
Status424(models::AnalyticsSinglePostResponse),
Status429(models::InlineObject4),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_analytics_dashboard`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAnalyticsDashboardError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(),
Status403(),
Status404(),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_analytics_delta`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAnalyticsDeltaError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
Status404(models::InlineObject2),
Status429(models::InlineObject4),
Status500(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_best_time_to_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBestTimeToPostError {
Status401(models::ErrorResponse),
Status403(models::GetBestTimeToPost403Response),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_content_decay`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetContentDecayError {
Status400(),
Status401(models::ErrorResponse),
Status403(models::GetBestTimeToPost403Response),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_daily_metrics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDailyMetricsError {
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_facebook_demographics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFacebookDemographicsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status404(models::InlineObject2),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_facebook_page_insights`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFacebookPageInsightsError {
Status400(),
Status401(models::ErrorResponse),
Status402(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_facebook_post_earnings`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFacebookPostEarningsError {
Status400(),
Status401(models::ErrorResponse),
Status402(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_facebook_post_reactions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFacebookPostReactionsError {
Status400(),
Status401(models::ErrorResponse),
Status404(),
Status502(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_follower_stats`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFollowerStatsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(models::GetFollowerStats403Response),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_google_analytics_metadata`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetGoogleAnalyticsMetadataError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(),
Status404(models::InlineObject2),
Status429(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_google_business_performance`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetGoogleBusinessPerformanceError {
Status400(models::GetGoogleBusinessPerformance400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::GetYouTubeDailyViews403Response),
Status502(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_google_business_search_keywords`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetGoogleBusinessSearchKeywordsError {
Status400(models::GetGoogleBusinessSearchKeywords400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::GetYouTubeDailyViews403Response),
Status502(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_instagram_account_insights`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetInstagramAccountInsightsError {
Status400(models::GetYouTubeDailyViews400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::GetYouTubeDailyViews403Response),
Status404(models::GetInstagramAccountInsights404Response),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_instagram_demographics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetInstagramDemographicsError {
Status400(models::GetYouTubeDailyViews400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::GetYouTubeDailyViews403Response),
Status404(models::GetInstagramAccountInsights404Response),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_instagram_follower_history`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetInstagramFollowerHistoryError {
Status400(),
Status401(models::ErrorResponse),
Status402(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_instagram_online_followers`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetInstagramOnlineFollowersError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
Status404(models::InlineObject2),
Status502(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_linked_in_aggregate_analytics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLinkedInAggregateAnalyticsError {
Status400(models::GetLinkedInAggregateAnalytics400Response),
Status401(models::ErrorResponse),
Status402(models::GetLinkedInAggregateAnalytics402Response),
Status403(models::GetLinkedInAggregateAnalytics403Response),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_linked_in_demographics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLinkedInDemographicsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status404(models::InlineObject2),
Status412(models::GetLinkedInDemographics412Response),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_linked_in_org_aggregate_analytics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLinkedInOrgAggregateAnalyticsError {
Status400(),
Status401(models::ErrorResponse),
Status402(),
Status403(),
Status404(),
Status412(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_linked_in_post_analytics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLinkedInPostAnalyticsError {
Status400(models::GetLinkedInPostAnalytics400Response),
Status401(models::ErrorResponse),
Status402(),
Status403(models::GetLinkedInPostAnalytics403Response),
Status404(models::GetLinkedInAggregateAnalytics402Response),
Status502(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_linked_in_post_reactions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLinkedInPostReactionsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_pinterest_account_insights`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPinterestAccountInsightsError {
Status400(),
Status401(models::ErrorResponse),
Status402(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_post_authenticity`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPostAuthenticityError {
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_post_samples`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPostSamplesError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_post_timeline`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPostTimelineError {
Status400(models::GetPostTimeline400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::GetPostTimeline403Response),
Status404(models::GetPostTimeline404Response),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_posting_frequency`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPostingFrequencyError {
Status401(models::ErrorResponse),
Status403(models::GetBestTimeToPost403Response),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_tik_tok_account_insights`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetTikTokAccountInsightsError {
Status400(),
Status401(models::ErrorResponse),
Status402(),
Status404(),
Status412(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_tik_tok_demographics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetTikTokDemographicsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status404(models::InlineObject2),
Status412(models::GetTikTokDemographics412Response),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_tracking_window`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetTrackingWindowError {
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_you_tube_channel_insights`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetYouTubeChannelInsightsError {
Status400(),
Status401(models::ErrorResponse),
Status402(),
Status404(),
Status412(models::YouTubeScopeMissingResponse),
Status429(models::ErrorResponse),
Status502(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_you_tube_daily_views`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetYouTubeDailyViewsError {
Status400(models::GetYouTubeDailyViews400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::GetYouTubeDailyViews403Response),
Status412(models::YouTubeScopeMissingResponse),
Status429(models::ErrorResponse),
Status500(models::GetYouTubeDailyViews500Response),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_you_tube_demographics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetYouTubeDemographicsError {
Status400(models::GetYouTubeDailyViews400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::GetYouTubeDailyViews403Response),
Status404(models::GetInstagramAccountInsights404Response),
Status412(models::GetYouTubeDemographics412Response),
Status429(models::ErrorResponse),
Status502(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_you_tube_video_retention`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetYouTubeVideoRetentionError {
Status400(models::GetYouTubeDailyViews400Response),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::GetYouTubeDailyViews403Response),
Status404(models::GetYouTubeVideoRetention404Response),
Status412(models::YouTubeScopeMissingResponse),
Status429(models::ErrorResponse),
Status500(models::GetYouTubeDailyViews500Response),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_facebook_tagged_posts`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFacebookTaggedPostsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status409(models::ErrorResponse),
Status422(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_facebook_visitor_posts`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFacebookVisitorPostsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status409(models::ErrorResponse),
Status422(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_post_authenticity`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListPostAuthenticityError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_tracking_windows`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListTrackingWindowsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
Status429(models::InlineObject4),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`open_tracking_window`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OpenTrackingWindowError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status402(models::GetAnalytics402Response),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`run_google_analytics_realtime_report`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RunGoogleAnalyticsRealtimeReportError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(),
Status404(models::InlineObject2),
Status429(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`run_google_analytics_report`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RunGoogleAnalyticsReportError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(),
Status404(models::InlineObject2),
Status429(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`sync_external_posts`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SyncExternalPostsError {
Status400(models::ErrorResponse),
Status401(),
Status403(),
Status404(models::ErrorResponse),
Status409(models::ErrorResponse),
Status502(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// Stops tracking and returns the window with its final status. A window that already completed keeps its `completed` status and its final read. A cancelled window gets no final read and fires no `post.tracking_completed` webhook.
pub async fn cancel_tracking_window(
configuration: &configuration::Configuration,
window_id: &str,
) -> Result<models::TrackingWindowResponse, Error<CancelTrackingWindowError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_window_id = window_id;
let uri_str = format!(
"{}/v1/analytics/tracking/{windowId}",
configuration.base_path,
windowId = crate::apis::urlencode(p_path_window_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TrackingWindowResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TrackingWindowResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CancelTrackingWindowError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns analytics for posts. With postId, returns a single post. Without it, returns a paginated list with overview stats. - Accepts both Zernio Post IDs and External Post IDs (auto-resolved). - fromDate defaults to 90 days ago if omitted, max range 366 days. - Single post lookups may return 202 (sync pending) or 424 (all platforms failed). - For follower stats, use /v1/accounts/follower-stats. - Accounts creators connected to your creator campaigns are left out, here and in every other analytics, follower-stats, account health, inbox and external posts read, unless the request names their profileId or accountId. ### LinkedIn personal accounts Analytics are only available for posts published through Zernio. LinkedIn's API only returns metrics for posts authored by the authenticated user. Organization/company page analytics work for all posts. ### Facebook Page stories Stories on a connected Page, published through Zernio or natively, are collected while they are live and returned like any other post (platformPostUrl points to the story). Metrics for a story published through Zernio are available on its Zernio post ID. Their lifetime metrics refresh about hourly, with a final reading shortly before the story expires at 24 hours. After that the values stay at that last reading. Mapping: - impressions = story media views (Meta stopped accepting per-story impressions in October 2026, so impressions equals views) - reach = unique story media viewers - views = story media views - likes = story reactions - comments = story replies - shares = story shares - clicks: always 0, because Meta exposes no link-click metric for stories
pub async fn get_analytics(
configuration: &configuration::Configuration,
post_id: Option<&str>,
platform: Option<&str>,
profile_id: Option<&str>,
account_id: Option<&str>,
source: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
limit: Option<i32>,
page: Option<i32>,
sort_by: Option<&str>,
order: Option<&str>,
tags: Option<&str>,
) -> Result<models::GetAnalytics200Response, Error<GetAnalyticsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_post_id = post_id;
let p_query_platform = platform;
let p_query_profile_id = profile_id;
let p_query_account_id = account_id;
let p_query_source = source;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_limit = limit;
let p_query_page = page;
let p_query_sort_by = sort_by;
let p_query_order = order;
let p_query_tags = tags;
let uri_str = format!("{}/v1/analytics", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_post_id {
req_builder = req_builder.query(&[("postId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_source {
req_builder = req_builder.query(&[("source", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_by {
req_builder = req_builder.query(&[("sortBy", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_order {
req_builder = req_builder.query(&[("order", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_tags {
req_builder = req_builder.query(&[("tags", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAnalytics200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetAnalytics200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAnalyticsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Everything an analytics dashboard needs in one call: window totals, follower growth, a per-day series, top posts, recent posts and, optionally, the same figures for the previous period. All dates are UTC days. ### Daily and total metrics Daily and total metrics use received attribution: each day holds the engagement that arrived that day, on any post. So `totals` is always the sum of `daily`. ### Post lists `topPosts` and `recentPosts` list posts published in the window with their lifetime metrics. A post cross-posted to several platforms appears once per platform.
pub async fn get_analytics_dashboard(
configuration: &configuration::Configuration,
from_date: String,
to_date: String,
profile_id: Option<&str>,
platform: Option<&str>,
compare: Option<&str>,
top_posts: Option<i32>,
recent_posts: Option<i32>,
) -> Result<models::GetAnalyticsDashboard200Response, Error<GetAnalyticsDashboardError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_profile_id = profile_id;
let p_query_platform = platform;
let p_query_compare = compare;
let p_query_top_posts = top_posts;
let p_query_recent_posts = recent_posts;
let uri_str = format!("{}/v1/analytics/dashboard", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("fromDate", &p_query_from_date.to_string())]);
req_builder = req_builder.query(&[("toDate", &p_query_to_date.to_string())]);
if let Some(ref param_value) = p_query_compare {
req_builder = req_builder.query(&[("compare", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_top_posts {
req_builder = req_builder.query(&[("topPosts", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_recent_posts {
req_builder = req_builder.query(&[("recentPosts", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAnalyticsDashboard200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetAnalyticsDashboard200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAnalyticsDashboardError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Cursor feed of the analytics snapshots that CHANGED, across every account you can read, in one paginated stream. Built for integrations that would otherwise call `GET /v1/analytics` once per connected account. Each page carries changes from many accounts at once, so your call count scales with how much actually changed rather than with how many accounts you have. Measured against a fleet of roughly 1,600 connected accounts: about 1,599 per-account analytics calls an hour became about 205 delta calls an hour, a 7.8x reduction. ### Bootstrap once, then stay in sync 1. Take the cursor FIRST: call this endpoint with NO `cursor`. It answers with an empty `data` array plus the feed's current position in `nextCursor`. 2. Load your baseline from `GET /v1/analytics`, the historical endpoint. This one is a rolling 7-day change log and cannot replay history. 3. Resume from the cursor you took before the baseline. Taking the cursor afterwards instead drops every change that lands while the baseline is loading: it is in neither the row you already read nor the feed you resume behind it. The overlap this order creates is safe. Metrics are absolute values rather than increments, so draining it leaves every post on its newest value. `nextCursor` is present on every response, empty pages included, so you always have something to advance with. ### Ordering Entries come back oldest first, in the order the feed received them. That order is NOT `syncedAt`. `syncedAt` is stamped when an account's sync cycle started, and a slow cycle writes its rows after a faster cycle that started later, so `syncedAt` can go backwards between consecutive entries. Do not sort, filter or resume on `syncedAt`. The cursor is the only stable position, and it is opaque: pass it back verbatim, and do not parse, construct or compare cursors. ### `hasMore: false` does not mean the feed ended This stream has no end and `nextCursor` is never null. - `hasMore: true`: more changes are already waiting, so call again straight away. - `hasMore: false`: you are caught up. Keep the cursor and poll again on your normal interval. ### The newest changes settle before they are served The feed deliberately holds back its last few seconds of writes, so that a row can never become visible behind a cursor you have already advanced past. A read issued the instant an `analytics.synced` webhook lands will therefore often return an empty page for that account. Do not read an empty page as \"nothing changed\": poll again with the SAME cursor you last used rather than advancing. ### Repeats inside one instant A sync cycle occasionally records the same post twice at the same feed position. When that happens the feed delivers one of those rows, not both. Measured over a day of production traffic, about 1.3% of rows fall in such a group and 99.4% of those groups are identical rows, so this is far more often deduplication than loss. Metrics are absolute values rather than increments, so a later entry for the same post supersedes an earlier one. ### Retention is 7 days Changes older than that leave the feed. A cursor older than 6 days is rejected with a `400` (a day of margin, because expiry is lazy). Recover the same way you bootstrapped: 1. Take a fresh cursor from a call to this endpoint with no `cursor`. 2. Re-load from `GET /v1/analytics`. 3. Resume from that cursor. A consumer that polls at least daily never reaches this. ### Webhook and access Pairs with the `analytics.synced` webhook, so changes can be read on notification instead of on a timer. That event carries no cursor of its own: keep using the `nextCursor` this endpoint gave you. Requires the same analytics access as `GET /v1/analytics`, and shares the stricter per-second rate-limit window applied to analytics endpoints.
pub async fn get_analytics_delta(
configuration: &configuration::Configuration,
cursor: Option<&str>,
limit: Option<i32>,
platform: Option<&str>,
profile_id: Option<&str>,
) -> Result<models::AnalyticsDeltaResponse, Error<GetAnalyticsDeltaError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_cursor = cursor;
let p_query_limit = limit;
let p_query_platform = platform;
let p_query_profile_id = profile_id;
let uri_str = format!("{}/v1/analytics/delta", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AnalyticsDeltaResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AnalyticsDeltaResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAnalyticsDeltaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the best times to post based on historical engagement data. Groups all published posts by day of week and hour (UTC), calculating average engagement per slot. Use this to auto-schedule posts at optimal times.
pub async fn get_best_time_to_post(
configuration: &configuration::Configuration,
platform: Option<&str>,
profile_id: Option<&str>,
account_id: Option<&str>,
source: Option<&str>,
) -> Result<models::GetBestTimeToPost200Response, Error<GetBestTimeToPostError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_platform = platform;
let p_query_profile_id = profile_id;
let p_query_account_id = account_id;
let p_query_source = source;
let uri_str = format!("{}/v1/analytics/best-time", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_source {
req_builder = req_builder.query(&[("source", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetBestTimeToPost200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetBestTimeToPost200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetBestTimeToPostError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns how engagement accumulates over time after a post is published. Each bucket shows what percentage of the post's total engagement had been reached by that time window. Useful for understanding content lifespan (e.g. \"posts reach 78% of total engagement within 24 hours\").
pub async fn get_content_decay(
configuration: &configuration::Configuration,
platform: Option<&str>,
profile_id: Option<&str>,
account_id: Option<&str>,
source: Option<&str>,
) -> Result<models::GetContentDecay200Response, Error<GetContentDecayError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_platform = platform;
let p_query_profile_id = profile_id;
let p_query_account_id = account_id;
let p_query_source = source;
let uri_str = format!("{}/v1/analytics/content-decay", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_source {
req_builder = req_builder.query(&[("source", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetContentDecay200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetContentDecay200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetContentDecayError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns daily aggregated analytics metrics and a per-platform breakdown. Each day includes post count, platform distribution, and summed metrics (impressions, reach, likes, comments, shares, saves, clicks, views). Defaults to the last 180 days. `totals` sums the whole range for the applied filters (pass `accountId` for one account). With attribution \"publish\" they are the lifetime metrics of posts published in the range, with \"received\" the engagement that arrived in the range.
pub async fn get_daily_metrics(
configuration: &configuration::Configuration,
platform: Option<&str>,
profile_id: Option<&str>,
account_id: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
source: Option<&str>,
attribution: Option<&str>,
) -> Result<models::GetDailyMetrics200Response, Error<GetDailyMetricsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_platform = platform;
let p_query_profile_id = profile_id;
let p_query_account_id = account_id;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_source = source;
let p_query_attribution = attribution;
let uri_str = format!("{}/v1/analytics/daily-metrics", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_source {
req_builder = req_builder.query(&[("source", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_attribution {
req_builder = req_builder.query(&[("attribution", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetDailyMetrics200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetDailyMetrics200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetDailyMetricsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the follower breakdown of a connected Facebook Page by country and/or city, from Meta's latest daily snapshot. ### Keys - Country keys are ISO 3166-1 alpha-2 codes. - City keys are \"City, Region, Country\" strings as Meta returns them. ### Limits Meta removed age and gender demographics for Pages (page_fans_gender_age) on November 15 2025 with no replacement, so only country and city are available. Meta reports small counts at a privacy floor, so the long tail can show identical low values.
pub async fn get_facebook_demographics(
configuration: &configuration::Configuration,
account_id: &str,
breakdown: Option<&str>,
) -> Result<models::GetFacebookDemographics200Response, Error<GetFacebookDemographicsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_breakdown = breakdown;
let uri_str = format!(
"{}/v1/analytics/facebook/demographics",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_breakdown {
req_builder = req_builder.query(&[("breakdown", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetFacebookDemographics200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetFacebookDemographics200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFacebookDemographicsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns page-level Facebook insights (media views, reach, views, post engagements, reaction counts, video metrics, follower counts). The response shape matches /v1/analytics/instagram/account-insights, so the same client handling works across platforms. Max 89 days, defaults to last 30 days. ### Metric names Metric names track the current (post-November 2025) Meta Graph API. These legacy metrics were deprecated by Meta on November 15, 2025 and are NOT accepted by this endpoint: - page_impressions - page_fans - page_fan_adds - page_fan_removes page_impressions_unique is deprecated above Graph API v25 and is not accepted; use page_total_media_view_unique. Meta's Page Insights reference (https://developers.facebook.com/docs/graph-api/reference/insights) also deprecates a number of Page Insights metrics for all API versions by June 15, 2026. Use the replacements below. Because Meta did not provide direct adds/removes replacements, Zernio synthesizes followers_gained / followers_lost from the daily follower snapshotter.
pub async fn get_facebook_page_insights(
configuration: &configuration::Configuration,
account_id: &str,
metrics: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
since: Option<String>,
until: Option<String>,
metric_type: Option<&str>,
) -> Result<models::InstagramAccountInsightsResponse, Error<GetFacebookPageInsightsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metrics = metrics;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_since = since;
let p_query_until = until;
let p_query_metric_type = metric_type;
let uri_str = format!(
"{}/v1/analytics/facebook/page-insights",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_since {
req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metric_type {
req_builder = req_builder.query(&[("metricType", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFacebookPageInsightsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns lifetime monetization earnings for ONE Facebook post, read live from Meta on every request. ### Lifetime totals only Earnings are CUMULATIVE since the post was published, not earnings within a date range. So this endpoint takes no since/until, and the totals must not be summed across dates or across posts. Page-level daily earnings live on /v1/analytics/facebook/page-insights. ### Zeros and missing metrics - A post on a Page that is not enrolled in monetization, or that earned nothing, returns \"total\": 0 rather than an error: Meta does not distinguish the two. - A metric Meta returned no bucket for at all is reported in \"unavailableMetrics\" and omitted from \"metrics\", never as a 0. Amounts are the platform's raw numbers in the stated \"unit\" and are never rescaled by Zernio. ### Rejected parameters These are rejected with 400: - \"breakdown\": breakdown dimensions are not exposed. - \"since\", \"until\", \"period\", and \"metricType\": scoping this endpoint to a window is not possible. Silently returning the lifetime total for a window would let a caller sum a year of weekly requests into a figure ~52x the post's real earnings.
pub async fn get_facebook_post_earnings(
configuration: &configuration::Configuration,
account_id: &str,
post_id: &str,
metrics: Option<&str>,
) -> Result<models::FacebookPostEarningsResponse, Error<GetFacebookPostEarningsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_post_id = post_id;
let p_query_metrics = metrics;
let uri_str = format!(
"{}/v1/analytics/facebook/post-earnings",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
req_builder = req_builder.query(&[("postId", &p_query_post_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FacebookPostEarningsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FacebookPostEarningsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFacebookPostEarningsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the reaction breakdown for a Facebook Page post: a count per reaction type plus the overall total. The whole breakdown is fetched in a single Graph call. The post analytics endpoint reports only an aggregate reaction count (surfaced there as `likes`), so use this endpoint when you need per-type counts.
pub async fn get_facebook_post_reactions(
configuration: &configuration::Configuration,
account_id: &str,
post_id: &str,
) -> Result<models::GetFacebookPostReactions200Response, Error<GetFacebookPostReactionsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_account_id = account_id;
let p_query_post_id = post_id;
let uri_str = format!(
"{}/v1/accounts/{accountId}/facebook-post-reactions",
configuration.base_path,
accountId = crate::apis::urlencode(p_path_account_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("postId", &p_query_post_id.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetFacebookPostReactions200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetFacebookPostReactions200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFacebookPostReactionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns follower count history and growth metrics for connected accounts. Requires analytics add-on subscription. Follower counts are refreshed once per day. ### Limits - At most 25 accounts per request: up to 25 `accountIds`, or a page of accounts. More than 25 `accountIds` returns 400. - Without `accountIds`, the response is the first page of 25 accounts even when `limit` and `cursor` are omitted. Pass `pagination.nextCursor` back as `cursor` for the next one. - When that default page cuts the list, the response also carries a `warning` and the headers `X-Result-Truncated: true` and `X-Result-Limit: 25`. - At most 1 year between `fromDate` and `toDate`. A longer range is cut to the year before `toDate`: `dateRange.from` shows where the data starts and the response carries a `warning`.
pub async fn get_follower_stats(
configuration: &configuration::Configuration,
account_ids: Option<&str>,
profile_id: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
granularity: Option<&str>,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::FollowerStatsResponse, Error<GetFollowerStatsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_ids = account_ids;
let p_query_profile_id = profile_id;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_granularity = granularity;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!("{}/v1/accounts/follower-stats", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_ids {
req_builder = req_builder.query(&[("accountIds", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_granularity {
req_builder = req_builder.query(&[("granularity", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FollowerStatsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FollowerStatsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFollowerStatsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Every dimension and metric the connected GA4 property accepts in a report, including its custom definitions. Cached for one hour.
pub async fn get_google_analytics_metadata(
configuration: &configuration::Configuration,
account_id: &str,
) -> Result<models::GetGoogleAnalyticsMetadata200Response, Error<GetGoogleAnalyticsMetadataError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let uri_str = format!(
"{}/v1/analytics/googleanalytics/metadata",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetGoogleAnalyticsMetadata200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetGoogleAnalyticsMetadata200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetGoogleAnalyticsMetadataError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns daily performance metrics for a Google Business Profile location. Metrics include impressions (Maps/Search, desktop/mobile), website clicks, call clicks, direction requests, conversations, bookings, and food orders. Data may be delayed 2-3 days. Max 18 months of historical data.
pub async fn get_google_business_performance(
configuration: &configuration::Configuration,
account_id: &str,
metrics: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
start_date: Option<String>,
end_date: Option<String>,
) -> Result<models::GetGoogleBusinessPerformance200Response, Error<GetGoogleBusinessPerformanceError>>
{
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metrics = metrics;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_start_date = start_date;
let p_query_end_date = end_date;
let uri_str = format!(
"{}/v1/analytics/googlebusiness/performance",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_start_date {
req_builder = req_builder.query(&[("startDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_end_date {
req_builder = req_builder.query(&[("endDate", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetGoogleBusinessPerformance200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetGoogleBusinessPerformance200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetGoogleBusinessPerformanceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns search keywords that triggered impressions for a Google Business Profile location. - Data is aggregated monthly. - Keywords Google reports only as below a threshold have `impressions` 0 and `impressionsThreshold` set to that threshold. - Max 18 months of historical data. ### Paging Returns up to 100 keywords per page. When `nextPageToken` is not null, pass it as `pageToken` with the same `startMonth` and `endMonth` to get the next page.
pub async fn get_google_business_search_keywords(
configuration: &configuration::Configuration,
account_id: &str,
start_month: Option<&str>,
end_month: Option<&str>,
page_token: Option<&str>,
) -> Result<
models::GetGoogleBusinessSearchKeywords200Response,
Error<GetGoogleBusinessSearchKeywordsError>,
> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_start_month = start_month;
let p_query_end_month = end_month;
let p_query_page_token = page_token;
let uri_str = format!(
"{}/v1/analytics/googlebusiness/search-keywords",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_start_month {
req_builder = req_builder.query(&[("startMonth", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_end_month {
req_builder = req_builder.query(&[("endMonth", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page_token {
req_builder = req_builder.query(&[("pageToken", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetGoogleBusinessSearchKeywords200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetGoogleBusinessSearchKeywords200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetGoogleBusinessSearchKeywordsError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns account-level Instagram insights such as reach, views, accounts engaged, and total interactions. These metrics reflect the entire account's performance across all content surfaces (feed, stories, explore, profile), and are fundamentally different from post-level metrics. - Data may be delayed up to 48 hours. - Max 90 days (30 for accounts connected through Facebook Login), defaults to last 30 days.
pub async fn get_instagram_account_insights(
configuration: &configuration::Configuration,
account_id: &str,
metrics: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
since: Option<String>,
until: Option<String>,
metric_type: Option<&str>,
breakdown: Option<&str>,
) -> Result<models::InstagramAccountInsightsResponse, Error<GetInstagramAccountInsightsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metrics = metrics;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_since = since;
let p_query_until = until;
let p_query_metric_type = metric_type;
let p_query_breakdown = breakdown;
let uri_str = format!(
"{}/v1/analytics/instagram/account-insights",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_since {
req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metric_type {
req_builder = req_builder.query(&[("metricType", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_breakdown {
req_builder = req_builder.query(&[("breakdown", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetInstagramAccountInsightsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns audience demographic insights for an Instagram account, broken down by age, city, country, and/or gender. Requires at least 100 followers. Returns top 45 entries per dimension. Data may be delayed up to 48 hours.
pub async fn get_instagram_demographics(
configuration: &configuration::Configuration,
account_id: &str,
metric: Option<&str>,
breakdown: Option<&str>,
timeframe: Option<&str>,
) -> Result<models::InstagramDemographicsResponse, Error<GetInstagramDemographicsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metric = metric;
let p_query_breakdown = breakdown;
let p_query_timeframe = timeframe;
let uri_str = format!(
"{}/v1/analytics/instagram/demographics",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metric {
req_builder = req_builder.query(&[("metric", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_breakdown {
req_builder = req_builder.query(&[("breakdown", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_timeframe {
req_builder = req_builder.query(&[("timeframe", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstagramDemographicsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InstagramDemographicsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetInstagramDemographicsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns a daily running Instagram follower count time series, served from Zernio's cross-platform daily snapshotter. Exists because Meta removed follower_count from the /insights endpoint in Graph API v22+ and never exposed a historical daily series via any public API. Response envelope matches /v1/analytics/instagram/account-insights so the same client handling works. Max 89 days, defaults to last 30 days.
pub async fn get_instagram_follower_history(
configuration: &configuration::Configuration,
account_id: &str,
metrics: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
since: Option<String>,
until: Option<String>,
metric_type: Option<&str>,
) -> Result<models::InstagramAccountInsightsResponse, Error<GetInstagramFollowerHistoryError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metrics = metrics;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_since = since;
let p_query_until = until;
let p_query_metric_type = metric_type;
let uri_str = format!(
"{}/v1/analytics/instagram/follower-history",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_since {
req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metric_type {
req_builder = req_builder.query(&[("metricType", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetInstagramFollowerHistoryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns how many of an Instagram account's followers were online in each hour, for every day of the last 30 days that Meta has data for. - Hour keys are \"0\" to \"23\" as Meta returns them. Meta does not document the timezone of the hour keys. - endTime is the end_time Meta returns for that day. - Data is delayed up to 48 hours, so the most recent days are left out until Meta fills them. - Requires at least 100 followers; for smaller accounts days is empty.
pub async fn get_instagram_online_followers(
configuration: &configuration::Configuration,
account_id: &str,
) -> Result<models::GetInstagramOnlineFollowers200Response, Error<GetInstagramOnlineFollowersError>>
{
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let uri_str = format!(
"{}/v1/analytics/instagram/online-followers",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetInstagramOnlineFollowers200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetInstagramOnlineFollowers200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetInstagramOnlineFollowersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns aggregate analytics across all posts for a LinkedIn personal account. Requires r_member_postAnalytics scope. Covers every post authored by the member, whether or not it was published through Zernio (LinkedIn aggregates by member, not by post). Org accounts should use /v1/analytics instead. Saves (POST_SAVE) and sends (POST_SEND) are available for personal accounts. Organization pages always return 0 for these two metrics because LinkedIn does not expose them on the organization analytics endpoint.
pub async fn get_linked_in_aggregate_analytics(
configuration: &configuration::Configuration,
account_id: &str,
aggregation: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
start_date: Option<String>,
end_date: Option<String>,
metrics: Option<&str>,
) -> Result<
models::GetLinkedInAggregateAnalytics200Response,
Error<GetLinkedInAggregateAnalyticsError>,
> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_account_id = account_id;
let p_query_aggregation = aggregation;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_start_date = start_date;
let p_query_end_date = end_date;
let p_query_metrics = metrics;
let uri_str = format!(
"{}/v1/accounts/{accountId}/linkedin-aggregate-analytics",
configuration.base_path,
accountId = crate::apis::urlencode(p_path_account_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_aggregation {
req_builder = req_builder.query(&[("aggregation", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_start_date {
req_builder = req_builder.query(&[("startDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_end_date {
req_builder = req_builder.query(&[("endDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetLinkedInAggregateAnalytics200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetLinkedInAggregateAnalytics200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLinkedInAggregateAnalyticsError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the lifetime follower breakdown of a connected LinkedIn organization page by job function, seniority, industry, company size, country and region. Without `breakdown` it returns function, seniority, industry and company size; country and region are returned only when requested. ### Labels - Function, seniority and industry are labelled with LinkedIn's standardized names (English) and keep the LinkedIn URN in `id`. - Company size is labelled as a range such as `2-10` or `10001+`. - Country and region are labelled with LinkedIn's geo names (English) and keep `urn:li:geo:*` in `id`. A region is a LinkedIn market area, for example New York City Metropolitan Area. LinkedIn returns at most the top 100 values per breakdown and leaves out followers whose profile lacks that field, so a breakdown does not add up to the follower count. ### Requirements - Organization accounts only: a personal LinkedIn account answers 400 `personal_account_not_supported`. - Requires the r_organization_social, r_organization_followers and r_organization_admin scopes (412 otherwise). - Requires the Analytics add-on.
pub async fn get_linked_in_demographics(
configuration: &configuration::Configuration,
account_id: &str,
breakdown: Option<&str>,
) -> Result<models::GetLinkedInDemographics200Response, Error<GetLinkedInDemographicsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_breakdown = breakdown;
let uri_str = format!(
"{}/v1/analytics/linkedin/demographics",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_breakdown {
req_builder = req_builder.query(&[("breakdown", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetLinkedInDemographics200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetLinkedInDemographics200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLinkedInDemographicsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns aggregate analytics for a LinkedIn organization page. Parallel to /v1/accounts/{id}/linkedin-aggregate-analytics (which handles personal accounts only). Backed by LinkedIn's organizationalEntityShareStatistics, organizationalEntityFollowerStatistics, and organizationPageStatistics endpoints. Response shape matches /v1/analytics/instagram/account-insights. Max 89 days, defaults to last 30 days. Scope requirements: r_organization_social, r_organization_followers, and r_organization_admin must all be present on the account. Accounts connected before these scopes were included in the OAuth flow will return 412 with a reauth hint. Enforced by this endpoint: - Page-view metrics accept only metricType=total_value (LinkedIn omits per-day segmentation even when the API is called with DAY granularity, so a time-series response would be meaningless). - Date range capped at 89 days. LinkedIn-side platform limits (not re-enforced here, but worth knowing for larger ranges in a future release): - Follower stats: rolling 12-month window, end must be no later than 2 days ago. - Share stats: rolling 12-month window.
pub async fn get_linked_in_org_aggregate_analytics(
configuration: &configuration::Configuration,
account_id: &str,
metrics: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
since: Option<String>,
until: Option<String>,
metric_type: Option<&str>,
) -> Result<models::InstagramAccountInsightsResponse, Error<GetLinkedInOrgAggregateAnalyticsError>>
{
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metrics = metrics;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_since = since;
let p_query_until = until;
let p_query_metric_type = metric_type;
let uri_str = format!(
"{}/v1/analytics/linkedin/org-aggregate-analytics",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_since {
req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metric_type {
req_builder = req_builder.query(&[("metricType", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLinkedInOrgAggregateAnalyticsError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns analytics for a specific LinkedIn post by URN. Works for both personal and organization accounts. Saves and sends are only populated for personal accounts (LinkedIn does not expose these metrics on the organization analytics endpoint).
pub async fn get_linked_in_post_analytics(
configuration: &configuration::Configuration,
account_id: &str,
urn: &str,
) -> Result<models::GetLinkedInPostAnalytics200Response, Error<GetLinkedInPostAnalyticsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_account_id = account_id;
let p_query_urn = urn;
let uri_str = format!(
"{}/v1/accounts/{accountId}/linkedin-post-analytics",
configuration.base_path,
accountId = crate::apis::urlencode(p_path_account_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("urn", &p_query_urn.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetLinkedInPostAnalytics200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetLinkedInPostAnalytics200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLinkedInPostAnalyticsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns individual reactions for a specific LinkedIn post, including reactor profiles (name, headline/job title, profile picture, profile URL, reaction type). Only works for organization/company page accounts. LinkedIn restricts reaction data for personal profiles (r_member_social_feed is a closed permission).
pub async fn get_linked_in_post_reactions(
configuration: &configuration::Configuration,
account_id: &str,
urn: &str,
limit: Option<i32>,
cursor: Option<i32>,
) -> Result<models::GetLinkedInPostReactions200Response, Error<GetLinkedInPostReactionsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_account_id = account_id;
let p_query_urn = urn;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!(
"{}/v1/accounts/{accountId}/linkedin-post-reactions",
configuration.base_path,
accountId = crate::apis::urlencode(p_path_account_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("urn", &p_query_urn.to_string())]);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetLinkedInPostReactions200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetLinkedInPostReactions200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLinkedInPostReactionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns account-level daily Pinterest metrics, read live from Pinterest's account analytics, plus the follower history from Zernio's daily snapshots. These are account totals. They include every pin on the account, also pins published long before the account was connected to Zernio, which per-post analytics cannot cover. - Response shape matches /v1/analytics/instagram/account-insights. - Defaults to the last 30 days. Pinterest serves at most the last 89 days, so a fromDate older than that returns 400. - Pinterest reports the latest 1-2 days as still processing. Those days are left out of values and totals until Pinterest settles them.
pub async fn get_pinterest_account_insights(
configuration: &configuration::Configuration,
account_id: &str,
metrics: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
since: Option<String>,
until: Option<String>,
metric_type: Option<&str>,
) -> Result<models::InstagramAccountInsightsResponse, Error<GetPinterestAccountInsightsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metrics = metrics;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_since = since;
let p_query_until = until;
let p_query_metric_type = metric_type;
let uri_str = format!(
"{}/v1/analytics/pinterest/account-insights",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_since {
req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metric_type {
req_builder = req_builder.query(&[("metricType", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetPinterestAccountInsightsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns Zernio's authenticity score for a post: an integer from 0 to 100 where higher means the view pattern looks more like organic viewing. The score is ours. It is computed only from the verified samples we fetched from the platform, never from anything the creator or caller reported. - `reasons` lists each factor that lowered it with its weight in points. - `confidence` (0 to 1) says how much data the score rests on. A stored score newer than 30 minutes is returned as is, otherwise it is recomputed. The `post.authenticity_changed` webhook fires when a score crosses 40.
pub async fn get_post_authenticity(
configuration: &configuration::Configuration,
post_id: &str,
) -> Result<models::PostAuthenticity, Error<GetPostAuthenticityError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_post_id = post_id;
let uri_str = format!(
"{}/v1/posts/{postId}/authenticity",
configuration.base_path,
postId = crate::apis::urlencode(p_path_post_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PostAuthenticity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PostAuthenticity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetPostAuthenticityError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the raw readings behind a post's numbers, oldest first. Each sample is one analytics sync: the views and engagement as the platform reported them at `syncedAt`. Zernio only stores what it fetched from the platform, so nothing here was self-reported. ### Null values - `shares` and `saves` are null on platforms that do not return that counter, which is different from a real zero. - `watchSeconds` and `completionRate` are null when the platform gives no watch signal.
pub async fn get_post_samples(
configuration: &configuration::Configuration,
post_id: &str,
from_date: Option<String>,
to_date: Option<String>,
limit: Option<i32>,
) -> Result<models::GetPostSamples200Response, Error<GetPostSamplesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_post_id = post_id;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_limit = limit;
let uri_str = format!("{}/v1/analytics/samples", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("postId", &p_query_post_id.to_string())]);
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPostSamples200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetPostSamples200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetPostSamplesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns a daily timeline of analytics metrics for a specific post, showing how impressions, likes, and other metrics evolved day-by-day since publishing. Each row represents one day of data per platform. For multi-platform Zernio posts, returns separate rows for each platform.
pub async fn get_post_timeline(
configuration: &configuration::Configuration,
post_id: &str,
from_date: Option<String>,
to_date: Option<String>,
) -> Result<models::GetPostTimeline200Response, Error<GetPostTimelineError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_post_id = post_id;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let uri_str = format!("{}/v1/analytics/post-timeline", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("postId", &p_query_post_id.to_string())]);
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPostTimeline200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetPostTimeline200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetPostTimelineError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the correlation between posting frequency (posts per week) and engagement rate, broken down by platform. Helps find the optimal posting cadence for each platform. Each row represents a specific (platform, posts_per_week) combination with the average engagement rate observed across all weeks matching that frequency.
pub async fn get_posting_frequency(
configuration: &configuration::Configuration,
platform: Option<&str>,
profile_id: Option<&str>,
account_id: Option<&str>,
source: Option<&str>,
) -> Result<models::GetPostingFrequency200Response, Error<GetPostingFrequencyError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_platform = platform;
let p_query_profile_id = profile_id;
let p_query_account_id = account_id;
let p_query_source = source;
let uri_str = format!("{}/v1/analytics/posting-frequency", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_source {
req_builder = req_builder.query(&[("source", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPostingFrequency200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetPostingFrequency200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetPostingFrequencyError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns account-level TikTok insights: the lifetime profile counters (live, with historical time series joined from Zernio's daily snapshotter) and TikTok's own daily account figures (video views, likes, comments, shares, profile views). - Response shape matches /v1/analytics/instagram/account-insights. - Max 89 days, defaults to last 30 days. - Requires the user.info.stats scope on the account (412 if missing). ### Daily account metrics `video_views`, `likes`, `comments`, `shares` and `profile_views` are TikTok's daily figures for the whole account, read from the TikTok Business Accounts API. They count every video of the account, not only recent ones, so they differ from GET /v1/analytics/daily-metrics, which sums per-post analytics. - With `metricType=time_series` each day is one entry in `values`. With `total_value` the total is the sum over the range. - The latest day available is yesterday, and TikTok can take 24-48 hours to settle a day. Days after the latest available one are left out of `values`. - They work for Business and personal TikTok accounts connected through Zernio's TikTok connection, with the user.insights scope. - Accounts on the original TikTok integration (or on your own TikTok app) cannot read them: each one is listed in `unavailableMetrics` with reason `unsupported_metric`, and reconnecting through Zernio's TikTok connection enables them. A grant without user.insights lists them with reason `permission_missing`. Either way the other requested metrics are still returned. - They are not in the default metric set: ask for them in `metrics`. ### What is not exposed This ACCOUNT-level endpoint does not return: - account-level impressions / reach - follower inflow / outflow breakdown - account-level watch time Follower age, gender, country and city are on GET /v1/analytics/tiktok/demographics. ### Per-video metrics PER-VIDEO is a different story on the Business lane. An account connected through the TikTok for Business app reports these per video on GET /v1/analytics?postId=...: - profile views, website clicks, follows - full-watched rate, watch time - impression sources, viewer types and viewer countries They arrive roughly 24-48h after publishing and only for posts active in the last 7 days. Accounts on the original TikTok integration get the basic counters there (views, likes, comments, shares) and zeros for the rest. They must reconnect through the Business app.
pub async fn get_tik_tok_account_insights(
configuration: &configuration::Configuration,
account_id: &str,
metrics: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
since: Option<String>,
until: Option<String>,
metric_type: Option<&str>,
) -> Result<models::InstagramAccountInsightsResponse, Error<GetTikTokAccountInsightsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metrics = metrics;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_since = since;
let p_query_until = until;
let p_query_metric_type = metric_type;
let uri_str = format!(
"{}/v1/analytics/tiktok/account-insights",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_since {
req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metric_type {
req_builder = req_builder.query(&[("metricType", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetTikTokAccountInsightsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the share of a TikTok account's followers by age, gender, country and city. Without `breakdown` it returns all four. - Each value is a share of followers from 0 to 1, and each list is sorted largest first. It is not a follower count. - Age, gender and country lists add up to 1. The city list can add up to less, because TikTok does not place every follower in a listed city. - These are followers of the account, not the viewers of its videos. Viewer countries per video are on GET /v1/analytics?postId=... - TikTok updates this data every 24-48 hours. ### Requirements - The account needs at least 100 followers (400 `tiktok_insufficient_followers` otherwise). - The account owner must turn on Analytics in the TikTok app and have published at least one video. Until then an account with enough followers gets empty lists. - Requires the user.insights scope, which an account gets by connecting through the TikTok for Business app (412 `tiktok_insights_scope_missing` otherwise). Accounts on the original TikTok integration must reconnect. - Requires the Analytics add-on.
pub async fn get_tik_tok_demographics(
configuration: &configuration::Configuration,
account_id: &str,
breakdown: Option<&str>,
) -> Result<models::GetTikTokDemographics200Response, Error<GetTikTokDemographicsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_breakdown = breakdown;
let uri_str = format!(
"{}/v1/analytics/tiktok/demographics",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_breakdown {
req_builder = req_builder.query(&[("breakdown", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetTikTokDemographics200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetTikTokDemographics200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetTikTokDemographicsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns one tracking window with the latest verified numbers we read from the platform. Once the window has completed, `finalReadAt` and `completionReason` say how it closed.
pub async fn get_tracking_window(
configuration: &configuration::Configuration,
window_id: &str,
) -> Result<models::TrackingWindowResponse, Error<GetTrackingWindowError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_window_id = window_id;
let uri_str = format!(
"{}/v1/analytics/tracking/{windowId}",
configuration.base_path,
windowId = crate::apis::urlencode(p_path_window_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TrackingWindowResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TrackingWindowResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetTrackingWindowError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns channel-scoped aggregate metrics from YouTube Analytics API v2. Saves you from looping /v1/analytics/youtube/daily-views over every video when you only need channel totals. Response shape matches /v1/analytics/instagram/account-insights so the same client handling works. Requires yt-analytics.readonly scope (412 with reauthorizeUrl if missing). Data has a 2-3 day delay (endDate is clamped accordingly). Max 89 days, defaults to last 30 days. NOT exposed: impressions (Studio thumbnail impressions) and impressionsClickThroughRate. YouTube Analytics API v2 does not expose these for any principal type, not channel owners, not Partner Program channels, not content owners with CMS access. The only way to get them is Studio CSV export. This is a Google-side limitation.
pub async fn get_you_tube_channel_insights(
configuration: &configuration::Configuration,
account_id: &str,
metrics: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
since: Option<String>,
until: Option<String>,
metric_type: Option<&str>,
) -> Result<models::InstagramAccountInsightsResponse, Error<GetYouTubeChannelInsightsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_metrics = metrics;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_since = since;
let p_query_until = until;
let p_query_metric_type = metric_type;
let uri_str = format!(
"{}/v1/analytics/youtube/channel-insights",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_metrics {
req_builder = req_builder.query(&[("metrics", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_since {
req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metric_type {
req_builder = req_builder.query(&[("metricType", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InstagramAccountInsightsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetYouTubeChannelInsightsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns daily view counts for a YouTube video including views, watch time, and subscriber changes. Requires yt-analytics.readonly scope (re-authorization may be needed). - YouTube finalizes analytics with a ~3-day delay. By default only finalized days are returned; an explicit endDate can reach into the delay window (see the endDate parameter). - Max 90 days, defaults to last 30 days.
pub async fn get_you_tube_daily_views(
configuration: &configuration::Configuration,
video_id: &str,
account_id: &str,
from_date: Option<String>,
to_date: Option<String>,
start_date: Option<String>,
end_date: Option<String>,
) -> Result<models::YouTubeDailyViewsResponse, Error<GetYouTubeDailyViewsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_video_id = video_id;
let p_query_account_id = account_id;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_start_date = start_date;
let p_query_end_date = end_date;
let uri_str = format!(
"{}/v1/analytics/youtube/daily-views",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("videoId", &p_query_video_id.to_string())]);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_start_date {
req_builder = req_builder.query(&[("startDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_end_date {
req_builder = req_builder.query(&[("endDate", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::YouTubeDailyViewsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::YouTubeDailyViewsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetYouTubeDailyViewsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns audience demographic insights for a YouTube channel, broken down by age, gender, and/or country. Pass videoId to get the audience profile of a single video instead of the whole channel. - Age and gender values are viewer percentages (0-100). - Country values are view counts. Data is based on signed-in viewers only, with a 2-3 day delay. YouTube suppresses demographics for videos with too few signed-in views, so low-traffic videos can return empty breakdowns.
pub async fn get_you_tube_demographics(
configuration: &configuration::Configuration,
account_id: &str,
video_id: Option<&str>,
breakdown: Option<&str>,
from_date: Option<String>,
to_date: Option<String>,
start_date: Option<String>,
end_date: Option<String>,
) -> Result<models::YouTubeDemographicsResponse, Error<GetYouTubeDemographicsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_video_id = video_id;
let p_query_breakdown = breakdown;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_start_date = start_date;
let p_query_end_date = end_date;
let uri_str = format!(
"{}/v1/analytics/youtube/demographics",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_video_id {
req_builder = req_builder.query(&[("videoId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_breakdown {
req_builder = req_builder.query(&[("breakdown", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_start_date {
req_builder = req_builder.query(&[("startDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_end_date {
req_builder = req_builder.query(&[("endDate", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::YouTubeDemographicsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::YouTubeDemographicsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetYouTubeDemographicsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the audience retention curve for a single YouTube video, plus the video's duration for rendering the curve on a time axis. Requires yt-analytics.readonly scope (re-authorization may be needed). ### The curve - Up to 100 points (elapsedVideoTimeRatio 0.01-1.0), aggregated over the whole date range. YouTube does not support per-day retention breakdowns. - audienceWatchRatio: the absolute share of viewers watching at that point in the video. It can exceed 1 (rewinds and looping, common on Shorts). - relativeRetentionPerformance: compares against videos of similar length (0 = worst, 0.5 = median, 1 = best). - Zernio returns exactly the buckets YouTube reports for the requested range and fills none in. A curve that ends before 1.0, or skips a position, means YouTube returned no row there for that range. - The range ends at toDate (default 3 days ago), so recent views are included only with a later toDate. ### Empty curves YouTube returns an empty curve for videos with very few views or before analytics processing completes (2-3 day delay). ### startedWatching and stoppedWatching YouTube does not return segment-level data for every video. Zernio then fetches the curve without it: `segmentMetricsAvailable` is `false` and both fields are `0` placeholders in every point. When it is `true`, a `0` is the value YouTube reported.
pub async fn get_you_tube_video_retention(
configuration: &configuration::Configuration,
video_id: &str,
account_id: &str,
from_date: Option<String>,
to_date: Option<String>,
start_date: Option<String>,
end_date: Option<String>,
) -> Result<models::YouTubeVideoRetentionResponse, Error<GetYouTubeVideoRetentionError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_video_id = video_id;
let p_query_account_id = account_id;
let p_query_from_date = from_date;
let p_query_to_date = to_date;
let p_query_start_date = start_date;
let p_query_end_date = end_date;
let uri_str = format!(
"{}/v1/analytics/youtube/video-retention",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("videoId", &p_query_video_id.to_string())]);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_from_date {
req_builder = req_builder.query(&[("fromDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to_date {
req_builder = req_builder.query(&[("toDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_start_date {
req_builder = req_builder.query(&[("startDate", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_end_date {
req_builder = req_builder.query(&[("endDate", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::YouTubeVideoRetentionResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::YouTubeVideoRetentionResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetYouTubeVideoRetentionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the public posts where other people or Pages tagged the connected Facebook Page, as Meta returns them from the Page's `tagged` edge. Cursor-paginated: pass `nextCursor` from the previous response as `cursor` to read the next page. `nextCursor` is null when there are no more pages. Meta does not say whether a page is the last one, so the final page can come back empty with `nextCursor` null. Works for `facebook` accounts with a Page selected. Meta needs the `pages_read_user_content` permission on the connection: a connection made without it gets Meta's refusal back as `platform_api_error`, and reconnecting the account grants it.
pub async fn list_facebook_tagged_posts(
configuration: &configuration::Configuration,
account_id: &str,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::ListFacebookTaggedPosts200Response, Error<ListFacebookTaggedPostsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_account_id = account_id;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!(
"{}/v1/accounts/{accountId}/facebook-tagged-posts",
configuration.base_path,
accountId = crate::apis::urlencode(p_path_account_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListFacebookTaggedPosts200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListFacebookTaggedPosts200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListFacebookTaggedPostsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns the posts other people published on the connected Facebook Page, newest first. A Page without visitor posts returns an empty `data` array. ### What is returned Zernio reads the Page feed (Graph `/{page-id}/feed`, which works on New Pages Experience Pages, unlike the deprecated `visitor_posts` edge). It drops: - the posts the Page published itself - the posts other people published on their own timeline that only tag the Page ### Pagination Cursor-paginated: pass `nextCursor` from the previous response as `cursor` to read the next page. `limit` sets how many feed entries are scanned, so a page can hold fewer posts than `limit`, or none, while `nextCursor` is not null. `nextCursor` is null when there are no more pages, and the final page can come back empty. ### Requirements Works on `facebook` accounts with a Page selected. Meta requires the `pages_read_user_content` permission, which Zernio requests with the comments scope. An account connected without it receives Meta's refusal as `platform_api_error`.
pub async fn list_facebook_visitor_posts(
configuration: &configuration::Configuration,
account_id: &str,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::ListFacebookVisitorPosts200Response, Error<ListFacebookVisitorPostsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_account_id = account_id;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!(
"{}/v1/accounts/{accountId}/facebook-visitor-posts",
configuration.base_path,
accountId = crate::apis::urlencode(p_path_account_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListFacebookVisitorPosts200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListFacebookVisitorPosts200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListFacebookVisitorPostsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Lists the stored authenticity scores for one connected account, newest first. Requires the Analytics add-on. Scores are 0 to 100 and come from Zernio's own model over verified platform samples. ### Filters - `minScore` and `maxScore`: find posts that look inflated. - `from` and `to`: bound when the score was computed.
pub async fn list_post_authenticity(
configuration: &configuration::Configuration,
account_id: &str,
min_score: Option<i32>,
max_score: Option<i32>,
from: Option<String>,
to: Option<String>,
limit: Option<i32>,
skip: Option<i32>,
) -> Result<models::ListPostAuthenticity200Response, Error<ListPostAuthenticityError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_min_score = min_score;
let p_query_max_score = max_score;
let p_query_from = from;
let p_query_to = to;
let p_query_limit = limit;
let p_query_skip = skip;
let uri_str = format!("{}/v1/analytics/authenticity", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("accountId", &p_query_account_id.to_string())]);
if let Some(ref param_value) = p_query_min_score {
req_builder = req_builder.query(&[("minScore", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_max_score {
req_builder = req_builder.query(&[("maxScore", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from {
req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to {
req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_skip {
req_builder = req_builder.query(&[("skip", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListPostAuthenticity200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListPostAuthenticity200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListPostAuthenticityError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Lists the tracking windows you can see, newest first. Each window carries the latest verified numbers we read from the platform.
pub async fn list_tracking_windows(
configuration: &configuration::Configuration,
account_id: Option<&str>,
status: Option<&str>,
limit: Option<i32>,
skip: Option<i32>,
) -> Result<models::ListTrackingWindows200Response, Error<ListTrackingWindowsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_status = status;
let p_query_limit = limit;
let p_query_skip = skip;
let uri_str = format!("{}/v1/analytics/tracking", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_status {
req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_skip {
req_builder = req_builder.query(&[("skip", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListTrackingWindows200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListTrackingWindows200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListTrackingWindowsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Starts watching a post's views and engagement. Zernio fetches the numbers from the platform itself on its regular analytics sync, so every reading is verified. It is a value we read from the platform, never one the creator or the caller reported. ### The window - Runs for `trackingDays` (30 by default, 90 at most). - Ends with one final read, after which the `post.tracking_completed` webhook fires. ### Identifying the post Send either `postId` (an external post id from Zernio), or `accountId` together with the post's `url`. ### Responses - `201`: a new window was opened. - `200`: the post is already tracked; the existing window is returned.
pub async fn open_tracking_window(
configuration: &configuration::Configuration,
open_tracking_window_request: models::OpenTrackingWindowRequest,
) -> Result<models::TrackingWindowResponse, Error<OpenTrackingWindowError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_open_tracking_window_request = open_tracking_window_request;
let uri_str = format!("{}/v1/analytics/tracking", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_open_tracking_window_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TrackingWindowResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TrackingWindowResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<OpenTrackingWindowError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Activity on a connected GA4 property in the last 30 minutes (up to 60 for Analytics 360), through Google's `runRealtimeReport`. Not cached. Only realtime dimensions and metrics are accepted, e.g. `country`, `unifiedScreenName` with `activeUsers`.
pub async fn run_google_analytics_realtime_report(
configuration: &configuration::Configuration,
run_google_analytics_realtime_report_request: models::RunGoogleAnalyticsRealtimeReportRequest,
) -> Result<models::GoogleAnalyticsReport, Error<RunGoogleAnalyticsRealtimeReportError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_run_google_analytics_realtime_report_request =
run_google_analytics_realtime_report_request;
let uri_str = format!(
"{}/v1/analytics/googleanalytics/realtime",
configuration.base_path
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_run_google_analytics_realtime_report_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GoogleAnalyticsReport`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GoogleAnalyticsReport`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RunGoogleAnalyticsRealtimeReportError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Runs a report on a connected GA4 property through Google's Data API (`runReport`). Pick any GA4 dimensions and metrics; filters and ordering use Google's own shapes. ### Caching and quota Identical requests on the same property are cached for 10 minutes. Google meters each property by quota tokens. When it is used up the request returns 429 until Google refills it (hourly quotas within the hour, daily ones at midnight Pacific time).
pub async fn run_google_analytics_report(
configuration: &configuration::Configuration,
run_google_analytics_report_request: models::RunGoogleAnalyticsReportRequest,
) -> Result<models::GoogleAnalyticsReport, Error<RunGoogleAnalyticsReportError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_run_google_analytics_report_request = run_google_analytics_report_request;
let uri_str = format!(
"{}/v1/analytics/googleanalytics/report",
configuration.base_path
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_run_google_analytics_report_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GoogleAnalyticsReport`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GoogleAnalyticsReport`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RunGoogleAnalyticsReportError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Fetch an account's latest external posts (published directly on the platform, not through Zernio) on demand. A newly published post is then retrievable within seconds instead of waiting for the background sync, which refreshes each account at most every ~90 minutes. Primary use case: verifying a submitted post. When a user publishes on the platform and immediately pastes the post URL into your app, call this with `accountId` plus `url` (or `postId`) to confirm the post exists and return its metadata. ### Behavior - Account access and connection state are checked before any platform call, including requests inside the debounce window. - Inactive accounts or accounts marked `needsReconnection` return `409` with code `ads_connection_required`. Stop scheduled retries for that account until it is reconnected, then read `GET /v1/accounts` for its current account ID. - For connected accounts, we fetch the latest posts live from the platform, then match and return the submitted post. - Requests are debounced per account (~15s): if the account was synced inside that window, the live fetch is skipped. ### Account and platforms `accountId` is required, because a post URL or id alone cannot be resolved to an account. The account must be connected to Zernio (we use its token to read the platform). Supported for every platform with a listing API: Instagram, Facebook, TikTok, YouTube, X, Threads, Pinterest, Reddit, Bluesky, Google Business Profile, and LinkedIn organization accounts. ### Locating the post `url` accepts any format the platform uses, for example: - `instagram.com/p/…`, `instagram.com/reel/…` - `youtu.be/…`, `youtube.com/shorts/…` - `tiktok.com/@user/video/…`, `vm.tiktok.com` short links - `pinterest.com/pin/…` on any regional domain, and `pin.it` short links Pass `postId` (the platform media/video/pin id) as an alternative locator. ### LinkedIn personal profiles LinkedIn has no listing API for personal profiles, so a `url` is REQUIRED and imports that single post. Pass any LinkedIn post URL (`linkedin.com/posts/…`, `linkedin.com/feed/update/urn:li:activity:…`) or a `urn:li:share:…` / `urn:li:ugcPost:…` URN. It works for posts published outside Zernio and before the account was connected, at any age. The post must be authored by the connected member. Imported posts return full analytics (impressions, reach, reactions, comments, reshares, saves) and keep refreshing on the background analytics cycle. They carry no content/media, since LinkedIn does not expose them for personal profiles. `publishedAt` comes from the post id: - An activity URL (`linkedin.com/feed/update/urn:li:activity:…`) carries the publication time. - A `urn:li:share:…` / `urn:li:ugcPost:…` URN only carries the creation time, which is earlier for a post scheduled in another tool. Pass the activity URL for the exact publication date. Importing it again for a post already imported by its URN corrects `publishedAt` on the same record. Right after an import, the per-post `GET /v1/analytics?postId=` read can show zeros for a few minutes while the metrics are ingested. This endpoint's response carries the fetched values immediately. ### TikTok Business accounts A `postId` or TikTok `url` that the listing has not stored is fetched from TikTok and imported as an external post, at any age, with its current metrics. ### Analytics delay Post-level analytics (reach, impressions) still carry the platform's own delay (e.g. ~24h on Instagram). This endpoint confirms the post exists and returns its metadata plus basic engagement (likes, comments), not delayed insights.
pub async fn sync_external_posts(
configuration: &configuration::Configuration,
sync_external_posts_request: models::SyncExternalPostsRequest,
) -> Result<models::SyncExternalPosts200Response, Error<SyncExternalPostsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_sync_external_posts_request = sync_external_posts_request;
let uri_str = format!("{}/v1/posts/sync-external", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_sync_external_posts_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SyncExternalPosts200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SyncExternalPosts200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SyncExternalPostsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}