Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 4c27a16

Browse files
cjbenavides88vinkla
authored andcommitted
Cjbenavides88 fetch media item comments (#102)
Created function to fetch comments from a media item.
1 parent e78afff commit 4c27a16

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ To fetch the user information data you may use the `self()` method.
6767
$instagram->self();
6868
```
6969

70+
To [fetch media item comments](https://www.instagram.com/developer/endpoints/comments/#get_media_comments) you may use the `comments()` method.
71+
72+
```php
73+
$instagram->comments('20033001112203311302_0102938816');
74+
```
75+
7076
> **Note:** You can only fetch a user's recent media from the given access token.
7177
7278
## Rate Limiting

src/Instagram.php

+14
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ public function media(array $parameters = []): array
8383
return $response->data;
8484
}
8585

86+
/**
87+
* Fetch comments from media item.
88+
*
89+
* @param string $mediaId
90+
*
91+
* @return array
92+
*/
93+
public function comments(string $mediaId) : array
94+
{
95+
$response = $this->get('media/'.$mediaId.'/comments');
96+
97+
return $response->data;
98+
}
99+
86100
/**
87101
* Fetch user information.
88102
*

tests/InstagramTest.php

+29-13
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,31 @@ public function testMedia()
4343
$this->assertCount(20, $items);
4444
}
4545

46+
public function testCanAppendParametersToMedia()
47+
{
48+
$response = new Response(200, [], json_encode([
49+
'data' => [],
50+
'meta' => [],
51+
]));
52+
53+
$client = new Client();
54+
$client->addResponse($response);
55+
56+
$instagram = new Instagram('jerryseinfeld', $client);
57+
$instagram->media([
58+
'count' => 22,
59+
'min_id' => 'min id',
60+
'max_id' => 'max id',
61+
]);
62+
63+
$request = $client->getLastRequest();
64+
65+
$this->assertSame(
66+
'access_token=jerryseinfeld&count=22&min_id=min+id&max_id=max+id',
67+
$request->getUri()->getQuery()
68+
);
69+
}
70+
4671
public function testSelf()
4772
{
4873
$response = new Response(200, [], json_encode([
@@ -59,29 +84,20 @@ public function testSelf()
5984
$this->assertIsObject($user);
6085
}
6186

62-
public function testCanAppendParametersToMedia()
87+
public function testComments()
6388
{
6489
$response = new Response(200, [], json_encode([
65-
'data' => [],
90+
'data' => range(1, 5),
6691
'meta' => [],
6792
]));
6893

6994
$client = new Client();
7095
$client->addResponse($response);
7196

7297
$instagram = new Instagram('jerryseinfeld', $client);
73-
$instagram->media([
74-
'count' => 22,
75-
'min_id' => 'min id',
76-
'max_id' => 'max id',
77-
]);
78-
79-
$request = $client->getLastRequest();
98+
$comments = $instagram->comments('media-id');
8099

81-
$this->assertSame(
82-
'access_token=jerryseinfeld&count=22&min_id=min+id&max_id=max+id',
83-
$request->getUri()->getQuery()
84-
);
100+
$this->assertIsArray($comments);
85101
}
86102

87103
public function testError()

0 commit comments

Comments
 (0)