Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always got "The value must be a valid insights metric" error #656

Open
amzar96 opened this issue Nov 5, 2023 · 2 comments
Open

Always got "The value must be a valid insights metric" error #656

amzar96 opened this issue Nov 5, 2023 · 2 comments

Comments

@amzar96
Copy link

amzar96 commented Nov 5, 2023

Background

I want to get my Facebook page insight. But, the metrics always change without notice in the changelog. Now I am not sure which metrics is not available.

Code snippet

METRICS = [
    # Exisiting Metrics
    "page_impressions_unique",
    "page_views_total",
    "page_fan_adds_unique",
    # Follow and Like
    "page_fans",
    # Page CTA Clicks
    "page_total_actions",
    # Page Engagement
    "page_engaged_users",
    "page_post_engagements",
    "page_consumptions",
    "page_consumptions_unique",
    "page_negative_feedback",
    "page_fans_online_per_day",
    "page_consumptions_by_consumption_type",
    "page_consumptions_by_consumption_type_unique",
    "page_negative_feedback_by_type",
    "page_negative_feedback_by_type_unique",
    "page_positive_feedback_by_type",
    "page_positive_feedback_by_type_unique",
    "page_fan_adds_by_paid_non_paid_unique",
    # Page Impressions
    "page_impressions",
    "page_impressions_paid",
    "page_impressions_paid_unique",
    "page_impressions_organic_v2",
    "page_impressions_organic_unique_v2",
    "page_impressions_viral",
    "page_impressions_viral_unique",
    "page_impressions_nonviral",
    "page_impressions_nonviral_unique",
    "page_video_views_by_paid_non_paid",
    "page_impressions_by_story_type",
    "page_impressions_by_story_type_unique",
    # Page Posts
    "page_posts_impressions",
    "page_posts_impressions_unique",
    "page_posts_impressions_paid",
    "page_posts_impressions_paid_unique",
    "page_posts_impressions_organic",
    "page_posts_impressions_organic_unique",
    "page_posts_served_impressions_organic_unique",
    "page_posts_impressions_viral",
    "page_posts_impressions_viral_unique",
    "page_posts_impressions_nonviral",
    "page_posts_impressions_nonviral_unique",
    # Page Reactions
    "page_actions_post_reactions_like_total",
    "page_actions_post_reactions_love_total",
    "page_actions_post_reactions_wow_total",
    "page_actions_post_reactions_haha_total",
    "page_actions_post_reactions_sorry_total",
    "page_actions_post_reactions_anger_total",
    "page_actions_post_reactions_total",
    # Page User Demographics
    "page_fans",
    "page_fan_adds",
    "page_fan_adds_unique",
    "page_fan_removes",
    "page_fan_removes_unique",
    "page_fans_locale",
    "page_fans_country",
    "page_fans_gender_age",
    "page_fans_city",
    "page_fans_by_like_source",
    "page_fans_by_like_source_unique",
    "page_fans_by_unlike_source_unique",
    # Page Video Views
    "page_video_views",
    "page_video_views_paid",
    "page_video_views_organic",
    "page_video_views_autoplayed",
    "page_video_views_click_to_play",
    "page_video_views_unique",
    "page_video_repeat_views",
    "page_video_complete_views_30s",
    "page_video_complete_views_30s_paid",
    "page_video_complete_views_30s_organic",
    "page_video_complete_views_30s_autoplayed",
    "page_video_complete_views_30s_click_to_play",
    "page_video_complete_views_30s_unique",
    "page_video_complete_views_30s_repeat_views",
    "page_video_view_time",
    "page_video_views_10s_paid",
    # "page_video_views_10s", # problem
    # "page_video_views_10s_organic", # problem
    # "page_video_views_10s_autoplayed", # problem
    # "page_video_views_10s_click_to_play", # problem
    # "page_video_views_10s_unique", # problem
    # "page_video_views_10s_repeat"
    # Page Views
    "page_views_logout",
    "page_views_logged_in_total",
    "page_views_logged_in_unique",
    "page_views_external_referrals",
    "page_views_by_profile_tab_total",
    "page_views_by_profile_tab_logged_in_unique",
    "page_views_by_internal_referer_logged_in_unique",
    "page_views_by_site_logged_in_unique",
    "page_views_by_age_gender_logged_in_unique",
    "page_views_by_referers_logged_in_unique",
    # Page Video Posts
    "post_video_views_organic",
    "post_video_views_paid",
    "post_video_views",
    # Stories
    "page_content_activity_by_action_type_unique",
    "page_content_activity",
    "page_content_activity_by_action_type",
]

def get_insight(page_id, date_start, date_stop):
    page_account = f"{page_id}"
    my_page = Page(page_account)

    print(Fore.YELLOW + f"Get insight from {date_start} to {date_stop}")

    data = my_page.get_insights(
        params={
            "since": date_start,
            "until": date_stop,
            "metric": METRICS,
            "period": "day",
        },
    )

    return data

Problem

When I ran the above code, I get this error

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v18.0/xxxx/insights
  Params:  {'since': '2023-10-29', 'until': '2023-11-05', 'metric': '["page_impressions_unique","page_views_total","page_fan_adds_unique","page_fans","page_total_actions","page_engaged_users","page_post_engagements","page_consumptions","page_consumptions_unique","page_negative_feedback","page_fans_online_per_day","page_consumptions_by_consumption_type","page_consumptions_by_consumption_type_unique","page_negative_feedback_by_type","page_negative_feedback_by_type_unique","page_positive_feedback_by_type","page_positive_feedback_by_type_unique","page_fan_adds_by_paid_non_paid_unique","page_impressions","page_impressions_paid","page_impressions_paid_unique","page_impressions_organic_v2","page_impressions_organic_unique_v2","page_impressions_viral","page_impressions_viral_unique","page_impressions_nonviral","page_impressions_nonviral_unique","page_video_views_by_paid_non_paid","page_impressions_by_story_type","page_impressions_by_story_type_unique","page_posts_impressions","page_posts_impressions_unique","page_posts_impressions_paid","page_posts_impressions_paid_unique","page_posts_impressions_organic","page_posts_impressions_organic_unique","page_posts_served_impressions_organic_unique","page_posts_impressions_viral","page_posts_impressions_viral_unique","page_posts_impressions_nonviral","page_posts_impressions_nonviral_unique","page_actions_post_reactions_like_total","page_actions_post_reactions_love_total","page_actions_post_reactions_wow_total","page_actions_post_reactions_haha_total","page_actions_post_reactions_sorry_total","page_actions_post_reactions_anger_total","page_actions_post_reactions_total","page_fans","page_fan_adds","page_fan_adds_unique","page_fan_removes","page_fan_removes_unique","page_fans_locale","page_fans_country","page_fans_gender_age","page_fans_city","page_fans_by_like_source","page_fans_by_like_source_unique","page_fans_by_unlike_source_unique","page_video_views","page_video_views_paid","page_video_views_organic","page_video_views_autoplayed","page_video_views_click_to_play","page_video_views_unique","page_video_repeat_views","page_video_complete_views_30s","page_video_complete_views_30s_paid","page_video_complete_views_30s_organic","page_video_complete_views_30s_autoplayed","page_video_complete_views_30s_click_to_play","page_video_complete_views_30s_unique","page_video_complete_views_30s_repeat_views","page_video_view_time","page_video_views_10s_paid","page_views_logout","page_views_logged_in_total","page_views_logged_in_unique","page_views_external_referrals","page_views_by_profile_tab_total","page_views_by_profile_tab_logged_in_unique","page_views_by_internal_referer_logged_in_unique","page_views_by_site_logged_in_unique","page_views_by_age_gender_logged_in_unique","page_views_by_referers_logged_in_unique","post_video_views_organic","post_video_views_paid","post_video_views","page_content_activity_by_action_type_unique","page_content_activity","page_content_activity_by_action_type"]', 'period': 'day'}

  Status:  400
  Response:
    {
      "error": {
        "message": "(#100) The value must be a valid insights metric",
        "type": "OAuthException",
        "code": 100,
        "fbtrace_id": "xxxx"
      }
    }

Also, when I want to get only page_impressions_unique metric still get the same error even though it shows in the docs.
image docs

    data = my_page.get_insights(
        params={
            "since": date_start,
            "until": date_stop,
            "metric": ['page_impressions_unique'],
            "period": "day",
        },

Error:

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v18.0/xxxx/insights
  Params:  {'since': '2023-10-29', 'until': '2023-11-05', 'metric': '["page_impressions_unique"]', 'period': 'day'}

  Status:  400
  Response:
    {
      "error": {
        "message": "(#100) The value must be a valid insights metric",
        "type": "OAuthException",
        "code": 100,
        "fbtrace_id": "xxxx"
      }
    }
@amzar96
Copy link
Author

amzar96 commented Feb 17, 2024

Any news?

@stcheng
Copy link
Contributor

stcheng commented Mar 1, 2024

Thank you for reporting this. Currently, the SDK does not have knowledge of which metrics are supported versus those that are not, and the list of metrics is not yet included in the SDK. We'll try to address this issue and, in the meantime, update the documentation to reflect the latest status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants