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

Cjbenavides88 fetch media item comments #102

Merged
merged 3 commits into from
Apr 11, 2019
Merged
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: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ To fetch the user information data you may use the `self()` method.
$instagram->self();
```

To [fetch media item comments](https://www.instagram.com/developer/endpoints/comments/#get_media_comments) you may use the `comments()` method.

```php
$instagram->comments('20033001112203311302_0102938816');
```

> **Note:** You can only fetch a user's recent media from the given access token.

## Rate Limiting
Expand Down
14 changes: 14 additions & 0 deletions src/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ public function media(array $parameters = []): array
return $response->data;
}

/**
* Fetch comments from media item.
*
* @param string $mediaId
*
* @return array
*/
public function comments(string $mediaId) : array
{
$response = $this->get('media/'.$mediaId.'/comments');

return $response->data;
}

/**
* Fetch user information.
*
Expand Down
42 changes: 29 additions & 13 deletions tests/InstagramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ public function testMedia()
$this->assertCount(20, $items);
}

public function testCanAppendParametersToMedia()
{
$response = new Response(200, [], json_encode([
'data' => [],
'meta' => [],
]));

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

$instagram = new Instagram('jerryseinfeld', $client);
$instagram->media([
'count' => 22,
'min_id' => 'min id',
'max_id' => 'max id',
]);

$request = $client->getLastRequest();

$this->assertSame(
'access_token=jerryseinfeld&count=22&min_id=min+id&max_id=max+id',
$request->getUri()->getQuery()
);
}

public function testSelf()
{
$response = new Response(200, [], json_encode([
Expand All @@ -59,29 +84,20 @@ public function testSelf()
$this->assertIsObject($user);
}

public function testCanAppendParametersToMedia()
public function testComments()
{
$response = new Response(200, [], json_encode([
'data' => [],
'data' => range(1, 5),
'meta' => [],
]));

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

$instagram = new Instagram('jerryseinfeld', $client);
$instagram->media([
'count' => 22,
'min_id' => 'min id',
'max_id' => 'max id',
]);

$request = $client->getLastRequest();
$comments = $instagram->comments('media-id');

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

public function testError()
Expand Down