:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(warehouse): use current Meta permission names for Instagram OAuth (#84435)
estefaniabd4595d8cae8
diff --git a/posthog/models/integration.py b/posthog/models/integration.pyindex 57371d99cf4f..7832d18a3d07 100644--- a/posthog/models/integration.py+++ b/posthog/models/integration.py@@ -511,15 +511,14 @@ def _raise_oauth_validation_error(kind: str, res: requests.Response) -> NoReturnERROR_TOKEN_REFRESH_FAILED = "TOKEN_REFRESH_FAILED"-# Graph API version the Instagram OAuth dialog, token exchange and refresh are pinned to. Kept in-# step with the warehouse Instagram source's `default_version`, which calls the same Graph version.-INSTAGRAM_GRAPH_API_VERSION = "v23.0"-# Instagram API with Facebook Login: the professional account is reached through the Facebook Page-# it is linked to, so the grant needs the page permissions as well as the Instagram ones.+# it is linked to, so the grant needs the page permissions as well as the Instagram ones. Meta+# replaced the legacy `instagram_*` permission names with `instagram_business_*`; the old names are+# rejected at the OAuth dialog ("This app needs at least one supported permission").# https://developers.facebook.com/docs/instagram-platform/instagram-api-with-facebook-loginINSTAGRAM_OAUTH_SCOPE = (- "instagram_basic instagram_manage_insights instagram_manage_comments pages_show_list pages_read_engagement"+ "instagram_business_basic instagram_business_manage_insights instagram_business_manage_comments"+ " pages_show_list pages_read_engagement")@@ -1241,9 +1240,9 @@ class OauthIntegration:# Meta app, but the two grants request different scopes so they stay separate kinds.# The token response carries no account identifier, so id/name come from `/me`.return OauthConfig(- authorize_url=f"https://www.facebook.com/{INSTAGRAM_GRAPH_API_VERSION}/dialog/oauth",- token_url=f"https://graph.facebook.com/{INSTAGRAM_GRAPH_API_VERSION}/oauth/access_token",- token_info_url=f"https://graph.facebook.com/{INSTAGRAM_GRAPH_API_VERSION}/me",+ authorize_url=f"https://www.facebook.com/{InstagramIntegration.api_version}/dialog/oauth",+ token_url=f"https://graph.facebook.com/{InstagramIntegration.api_version}/oauth/access_token",+ token_info_url=f"https://graph.facebook.com/{InstagramIntegration.api_version}/me",token_info_config_fields=["id", "name"],client_id=settings.INSTAGRAM_APP_CLIENT_ID,client_secret=settings.INSTAGRAM_APP_CLIENT_SECRET,@@ -4192,7 +4191,6 @@ class MetaAdsIntegration(MetaGraphIntegration):class InstagramIntegration(MetaGraphIntegration):kind = "instagram"- api_version = INSTAGRAM_GRAPH_API_VERSIONclass TwilioIntegration:diff --git a/posthog/models/test/test_integration_model.py b/posthog/models/test/test_integration_model.pyindex 776f3326d653..92222572fb31 100644--- a/posthog/models/test/test_integration_model.py+++ b/posthog/models/test/test_integration_model.py@@ -4765,9 +4765,11 @@ class TestInstagramIntegrationModel(BaseTest):def test_oauth_config(self):config = OauthIntegration.oauth_config_for_kind("instagram")- assert config.authorize_url == "https://www.facebook.com/v23.0/dialog/oauth"- assert config.token_url == "https://graph.facebook.com/v23.0/oauth/access_token"- assert config.token_info_url == "https://graph.facebook.com/v23.0/me"+ # Same Graph version as the other Meta kinds: an older pin here makes the OAuth dialog+ # reject the permission set before anyone reaches a consent screen.+ assert config.authorize_url == "https://www.facebook.com/v25.0/dialog/oauth"+ assert config.token_url == "https://graph.facebook.com/v25.0/oauth/access_token"+ assert config.token_info_url == "https://graph.facebook.com/v25.0/me"assert config.client_id == "instagram-client-id"assert config.client_secret == "instagram-client-secret"assert config.id_path == "id"@@ -4775,9 +4777,9 @@ class TestInstagramIntegrationModel(BaseTest):# Instagram is reached through the Facebook page it is linked to, so the page scopes# are as load-bearing as the Instagram ones.assert set(config.scope.split(" ")) == {- "instagram_basic",- "instagram_manage_insights",- "instagram_manage_comments",+ "instagram_business_basic",+ "instagram_business_manage_insights",+ "instagram_business_manage_comments","pages_show_list","pages_read_engagement",}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/tests/test_instagram_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/tests/test_instagram_source.pyindex 633d75f8d4c8..80b82081107a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/tests/test_instagram_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/tests/test_instagram_source.py@@ -96,9 +96,9 @@ class TestInstagramSource:# be able to tell the user which grant is missing.assert integration.requiredScopes is not Noneassert set(integration.requiredScopes.split(" ")) == {- "instagram_basic",- "instagram_manage_insights",- "instagram_manage_comments",+ "instagram_business_basic",+ "instagram_business_manage_insights",+ "instagram_business_manage_comments","pages_show_list","pages_read_engagement",}