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

added insights endpoint mixin #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions instagram_private_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ConnectionError(Exception):
MiscEndpointsMixin, LocationsEndpointsMixin, TagsEndpointsMixin,
UsersEndpointsMixin, UploadEndpointsMixin, UsertagsEndpointsMixin,
CollectionsEndpointsMixin, HighlightsEndpointsMixin,
IGTVEndpointsMixin,
IGTVEndpointsMixin, InsightsEndpointsMixin,
ClientDeprecationWarning, ClientPendingDeprecationWarning,
ClientExperimentalWarning
)
Expand All @@ -60,7 +60,7 @@ class Client(AccountsEndpointsMixin, DiscoverEndpointsMixin, FeedEndpointsMixin,
MiscEndpointsMixin, LocationsEndpointsMixin, TagsEndpointsMixin,
UsersEndpointsMixin, UploadEndpointsMixin, UsertagsEndpointsMixin,
CollectionsEndpointsMixin, HighlightsEndpointsMixin,
IGTVEndpointsMixin, object):
IGTVEndpointsMixin, InsightsEndpointsMixin, object):
"""Main API client class for the private app api."""

API_URL = 'https://i.instagram.com/api/{version!s}/'
Expand Down Expand Up @@ -546,7 +546,7 @@ def _call_api(self, endpoint, params=None, query=None, return_response=False, un
error_response=json.dumps(json_response))

# not from oembed or an ok response
if not json_response.get('provider_url') and json_response.get('status', '') != 'ok':
if not json_response.get('provider_url') and json_response.get('status', '') != 'ok' and not json_response.get('data', ''):
raise ClientError(
json_response.get('message', 'Unknown error'), code=response.code,
error_response=json.dumps(json_response))
Expand Down
1 change: 1 addition & 0 deletions instagram_private_api/endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .collections import CollectionsEndpointsMixin
from .highlights import HighlightsEndpointsMixin
from .igtv import IGTVEndpointsMixin
from .insights import InsightsEndpointsMixin

from .common import (
ClientDeprecationWarning,
Expand Down
34 changes: 34 additions & 0 deletions instagram_private_api/endpoints/insights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import json


class InsightsEndpointsMixin(object):
"""For endpoints in related to insights functionality."""

def insights(self):
"""
Get insights
:param day:
:return:
"""

params = {
'locale': 'en_US',
'vc_policy': 'insights_policy',
'surface': 'account',
'access_token': 'undefined',
'fb_api_caller_class': 'RelayModern',
'variables': json.dumps({
'IgInsightsGridMediaImage_SIZE': 240,
'timezone': 'Asia/Jakarta',
'activityTab': 'true',
'audienceTab': 'true',
'contentTab': 'true',
'query_params': json.dumps({
'access_token': '',
'id': self.authenticated_user_id
})
}),
'doc_id': '1926322010754880'
}
res = self._call_api('ads/graphql/', query=params, unsigned=True)
return res