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.

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 %}
2
  • 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 0: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 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.