Skip to content

Commit 3a2befe

Browse files
committed
Add story_viewers endpoint
1 parent 93363b0 commit 3a2befe

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Refactored error detection. New ``ClientCheckpointRequiredError``, ``ClientChallengeRequiredError``, ``ClientSentryBlockError``
66
* New highlight endpoints
77
* New ``comment_inline_replies()`` endpoint
8+
* New ``story_viewers()`` endpoint
89
* Updates for user feed and comments endpoints
910

1011
## 1.4.0

instagram_private_api/endpoints/media.py

+13
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,16 @@ def media_undo_only_me(self, media_id, media_type):
564564
:param media_type: One of :attr:`MediaTypes.PHOTO`, :attr:`MediaTypes.VIDEO`, or :attr:`MediaTypes.CAROUSEL`
565565
"""
566566
return self.media_only_me(media_id, media_type, undo=True)
567+
568+
def story_viewers(self, story_pk, **kwargs):
569+
"""
570+
Get list of story viewers
571+
572+
:param story_pk: Story media's PK identifier, e.g. "1700000123"
573+
:param kwargs:
574+
**max_id**: For pagination
575+
:return:
576+
"""
577+
endpoint = 'media/{story_pk!s}/list_reel_media_viewer/'.format(
578+
story_pk=story_pk)
579+
return self._call_api(endpoint, query=kwargs)

tests/private/client.py

-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ def test_client_requests(self, open_mock):
256256
}).encode('ascii'))),
257257
MockResponse(body=json.dumps({'message': 'login_required'})),
258258
MockResponse(body=json.dumps({'status': 'error'})),
259-
260259
]
261260

262261
with self.assertRaises(ClientLoginRequiredError) as ce:

tests/private/media.py

+25
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ def init_all(api):
170170
'name': 'test_comment_inline_replies',
171171
'test': MediaTests('test_comment_inline_replies', api)
172172
},
173+
{
174+
'name': 'test_story_viewers_mock',
175+
'test': MediaTests('test_story_viewers_mock', api)
176+
},
177+
{
178+
'name': 'test_story_viewers',
179+
'test': MediaTests('test_story_viewers', api)
180+
},
173181
]
174182

175183
def test_media_info(self):
@@ -559,3 +567,20 @@ def test_media_only_me_mock(self, call_api):
559567
call_api.assert_called_with(
560568
'media/{media_id!s}/undo_only_me/'.format(**{'media_id': media_id}),
561569
params=params, query={'media_type': 2})
570+
571+
@compat_mock.patch('instagram_private_api.Client._call_api')
572+
def test_story_viewers_mock(self, call_api):
573+
call_api.return_value = {'status': 'ok'}
574+
story_pk = '170000000'
575+
self.api.story_viewers(story_pk)
576+
call_api.assert_called_with(
577+
'media/{story_pk!s}/list_reel_media_viewer/'.format(story_pk=story_pk),
578+
query={})
579+
580+
@unittest.skip('Requires valid story PK.')
581+
def test_story_viewers(self):
582+
results = self.api.story_viewers('170000000123')
583+
self.assertEqual(results.get('status'), 'ok')
584+
self.assertIn('users', results)
585+
self.assertIn('total_viewer_count', results)
586+
self.assertIn('user_count', results)

0 commit comments

Comments
 (0)