2
{% set tweets = craft.twitter.get('statuses/user_timeline', { tweet_mode:'extended' }) %}

{% for tweet in tweets %}
    <li>

    {% if tweet.extended_entities.media is defined %}
        {% for item in tweet.extended_entities.media if item.type == 'photo' %}
            <img src="{{ item.media_url }}">
        {% endfor %}
    {% endif %}

    </li>
{% endfor %}

Anything obviously wrong here? I tested the API with a {{ dump(tweets) }} which seems fine.

This thread describes a similar issue but without a solution.

Nutmeg
  • 598
  • 1
  • 4
  • 17

1 Answers1

2

The return from craft.twitter.get() is not an array of tweets, but a response object, where the actual tweets are nested in an attribute called data.

Not tested, but from looking at the plugin docs, something like this should do it:

{% set response = craft.twitter.get('statuses/user_timeline', { tweet_mode:'extended' }) %}

{% if response.success %}
    {% for tweet in response.data %}
        ...
    {% endfor %}
{% endif %}
Mats Mikkel Rummelhoff
  • 22,361
  • 3
  • 38
  • 69
  • 1
    Thank you for explaining, Mats. The images are showing now, albeit unlimited versions from each, per list item line. Not sure how to limit the output when a for loop includes a conditional... – Nutmeg Aug 17 '18 at 00:16
  • 1
    @Nutmeg Not sure I follow, sorry. If you're talking about limiting the number of tweets, you could use the count parameter, i.e. craft.twitter.get('statuses/user_timeline', { tweet_mode: 'extended', count: 5 }). – Mats Mikkel Rummelhoff Aug 17 '18 at 06:56