Skip to content

Commit

Permalink
add hasAudio, thumbnail and image attritbute
Browse files Browse the repository at this point in the history
  • Loading branch information
kringkaste committed Feb 16, 2021
1 parent ddb9fb2 commit a1099cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## Unreleased
### Added
- Enable environment variables for setting username (thanks to @niektenhoopen)
- Adding rel noopener and noreferrer properties to links (thanks to @JayBox325)
- Add rel noopener and noreferrer properties to links (thanks to @JayBox325)
- Add full image URL
- Add hasAudio attribute

### Changed
- Prevent request storm if no items are cached and the request failed.
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To fetch the feed, configured in settings, in your template, just iterate like t
``` twig
{% for item in craft.instagram.getFeed() %}
<a href="https://www.instagram.com/p/{{ item.shortcode }}/" target="_blank" rel="noopener noreferrer">
<img src="{{ item.src }}" alt="" />
<img src="{{ item.thumbnail }}" alt="" />
</a>
<p>{{ item.caption }}</p>
<p>{{ item.likes }} Likes / {{ item.comments }} Comments</p>
Expand All @@ -45,6 +45,23 @@ In PHP do:
``` php
$feed = InstagramFeed::getInstance()->instagramService->getFeed();
```
The function returns an array of posts with the following keys:

``` php
[
'src' => '', # Best available thumbnail
'thumbnail' = '', # Same as src
'image' => '', # The original image
'likes' => 0, # Number of likes
'comments' => 0, # Number of comments
'shortcode' => '', # The IG shortcode for the post
'timestamp' => 0, # Unix timestamp when the picture/ video was taken
'caption' => '', # The caption of the post
'isVideo' => false, # If the post is a video
'hasAudio' => false # If the video has audio
'video_view_count' => 0, # Number of video views
]
```

You can also get the current configured Instagram account (or hash tag) in your templates:

Expand Down
3 changes: 3 additions & 0 deletions src/services/InstagramService.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,15 @@ private function flattenMediaArray($mediaArray): array

foreach ($mediaArray as $media) {
$item['src'] = $this->getBestPicture($media['node']['thumbnail_resources']);
$item['thumbnail'] = $item['src'];
$item['image'] = $media['node']['display_url'];
$item['likes'] = $media['node']['edge_liked_by']['count'];
$item['comments'] = $media['node']['edge_media_to_comment']['count'];
$item['shortcode'] = $media['node']['shortcode'];
$item['timestamp'] = $media['node']['taken_at_timestamp'];
$item['caption'] = $media['node']['edge_media_to_caption']['edges'][0]['node']['text'] ?? '';
$item['isVideo'] = (bool)$media['node']['is_video'];
$item['hasAudio'] = (bool)$media['node']['has_audio'];
$item['video_view_count'] = $media['node']['video_view_count'] ?? 0;
$items[] = $item;
}
Expand Down

0 comments on commit a1099cb

Please sign in to comment.