<p>That error basically means that you're trying to use the variable <code>tweet</code> as an object/iterable, but it's actually just a boolean (true/false). </p>

<p>Assuming the plugin you're using (i.e. <code>craft.twitter</code>) is <a href="https://github.com/dukt/twitter" rel="nofollow noreferrer">Dukt's Twitter plugin</a>, I think this is just a matter of your syntax being a bit off. The Dukt plugin's <code>craft.twitter.get()</code> method actually returns a response object where the 
tweet objects are <em>nested</em> in an array called <code>data</code>. In other words, you can't loop on the object returned by <code>craft.twitter.get()</code> directly; you'll need to use the array in that object's <code>data</code> property:</p>

<pre><code>{% set response = craft.twitter.get('statuses/user_timeline', {count:2}) %}

{% if response.success %}
    {% set tweets = response.data %}
    {% for tweet in tweets %}
        {% set tweetDate = date(tweet.created_at).diff(now).format('%a') %}
        ...
    {% endfor %}
{% else %}
    &lt;p&gt;An error occured:&lt;/p&gt;
    &lt;pre&gt;{{ response.data|json_encode(constant('JSON_PRETTY_PRINT')) }}&lt;/pre&gt;
{% endif %}
</code></pre>

<p>The above example is lifted from <a href="https://docs.dukt.net/twitter/v2/craft-twitter.html#get-uri-query-headers-options-enablecache-cacheexpire" rel="nofollow noreferrer">the plugin's documentation</a> (although in the actual docs there's a typo, which could well be the cause for your issue). Note that the example also accounts for Things Going Wrong (tm), which is always a good idea when you're working with a third party API.</p>

<p>If the plugin you're using is <em>not</em> Dukt's, you'll need to check your plugin's documentation, to verify you're using it correctly. As a debugging effort, you might also want to try and <a href="http://twig.sensiolabs.org/doc/functions/dump.html" rel="nofollow noreferrer"><code>dump()</code></a> the response object variable to verify that it contains what you think it contains:</p>

<pre><code>{% set tweets = craft.twitter.get('statuses/user_timeline', {count:2}) %}
{{ dump(tweets) }}
</code></pre>

<p><em>Note that the <code>dump()</code> method only works when <a href="https://craftcms.com/support/dev-mode" rel="nofollow noreferrer"><code>devMode</code></a> is set to <code>true</code>, and should not be left in production code.</em></p>

CC BY-SA 4.0
2018-08-01T19:47:52.040Z
Thank you, Mats for providing clarity and outcome! I did use Dukt's Twitter example and could not figure out the error - the typo explains it....
Nutmeg
CC BY-SA 4.0
2018-08-01T18:27:36.660Z
2018-08-01T18:27:36.660Z
Mats Mikkel Rummelhoff
<p>I have read a number of related threads but am still puzzled what this error actually means or how to fix it.</p>

<p>This triggers the error:</p>

<pre><code>&lt;div class="twitter"&gt;

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

               {% if tweets %}
                 &lt;h3 class="title"&gt;Latest Tweets&lt;/h3&gt;
                 &lt;div class="line-orange-l"&gt;&lt;/div&gt;



                  &lt;ul&gt;
                    {% for tweet in tweets %}
                    {% set tweetDate = date(tweet.created_at).diff(now).format('%a') %}
                    {% if tweetDate == 0 %}
                    {% set tweetTimeAgo = 'today' %}
                    {% else %}
                    {% set tweetTimeAgo = tweetDate ~ ' days ago' %}
                    {% endif %}
                    &lt;li&gt;
                       &lt;p&gt;
                          &lt;i class="fa fa-twitter" aria-hidden="true"&gt;&lt;/i&gt;
                          {{ tweet.text|autoLinkTweet }}&lt;br&gt;
                          &lt;a href="http://twitter.com/{{ tweet.user.screen_name|raw }}" class="author"&gt;@{{ tweet.user.screen_name|raw }}&lt;/a&gt; /
                          &lt;span class="posted"&gt;Posted {{ tweetTimeAgo }}&lt;/span&gt;
                       &lt;/p&gt;
                    &lt;/li&gt;
                    {% endfor %}
                  &lt;/ul&gt;
                  {% endif %}
                 &lt;/ul&gt;
              &lt;/div&gt;
</code></pre>

<p>What would fix this?</p>

CC BY-SA 4.0
2018-08-01T12:07:33.127Z
A good fix would be defensive coding and checking if the variables exist https://nystudio107.com/blog/handling-errors-gracefully-in-craft-cms#defensive-coding-in-twig
Robin Schambach
CC BY-SA 4.0
2018-08-01T19:56:50.353Z
Thank you, Robin. I was not aware of the Twig ?? null coa­lesc­ing oper­a­tor, which makes total sense to incorporate as a standard.
Nutmeg
<createcommand>
Impossible to access an attribute ("created_at") on a boolean variable ("1")
# Impossible to access an attribute ("created_at") on a boolean variable ("1")

(Asked by: username_0 on 2018-08-01)

I have read a number of related threads but am still puzzled what this error actually means or how to fix it.
This triggers the error:


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

               {% if tweets %}
                 Latest Tweets
                 



                  
                    {% for tweet in tweets %}
                    {% set tweetDate = date(tweet.created_at).diff(now).format('%a') %}
                    {% if tweetDate == 0 %}
                    {% set tweetTimeAgo = 'today' %}
                    {% else %}
                    {% set tweetTimeAgo = tweetDate ~ ' days ago' %}
                    {% endif %}
                    
                       
                          
                          {{ tweet.text|autoLinkTweet }}
                          @{{ tweet.user.screen_name|raw }} /
                          Posted {{ tweetTimeAgo }}
                       
                    
                    {% endfor %}
                  
                  {% endif %}
                 
              

What would fix this?

**Tags:** createcommand

> **Comments:**
> **username_1**: A good fix would be defensive coding and checking if the variables exist https://nystudio107.com/blog/handling-errors-gracefully-in-craft-cms#defensive-coding-in-twig  
> **username_0**: Thank you, Robin. I was not aware of the Twig ?? null coa­lesc­ing oper­a­tor, which makes total sense to incorporate as a standard.  

---

## 1 answers

### Answer by username_2 on 2018-08-01. Score: 1 | Accepted answer

That error basically means that you're trying to use the variable tweet as an object/iterable, but it's actually just a boolean (true/false). 
Assuming the plugin you're using (i.e. craft.twitter) is Dukt's Twitter plugin, I think this is just a matter of your syntax being a bit off. The Dukt plugin's craft.twitter.get() method actually returns a response object where the 
tweet objects are nested in an array called data. In other words, you can't loop on the object returned by craft.twitter.get() directly; you'll need to use the array in that object's data property:
{% set response = craft.twitter.get('statuses/user_timeline', {count:2}) %}

{% if response.success %}
    {% set tweets = response.data %}
    {% for tweet in tweets %}
        {% set tweetDate = date(tweet.created_at).diff(now).format('%a') %}
        ...
    {% endfor %}
{% else %}
    An error occured:
    {{ response.data|json_encode(constant('JSON_PRETTY_PRINT')) }}
{% endif %}

The above example is lifted from the plugin's documentation (although in the actual docs there's a typo, which could well be the cause for your issue). Note that the example also accounts for Things Going Wrong (tm), which is always a good idea when you're working with a third party API.
If the plugin you're using is not Dukt's, you'll need to check your plugin's documentation, to verify you're using it correctly. As a debugging effort, you might also want to try and dump() the response object variable to verify that it contains what you think it contains:
{% set tweets = craft.twitter.get('statuses/user_timeline', {count:2}) %}
{{ dump(tweets) }}

Note that the dump() method only works when devMode is set to true, and should not be left in production code.

> **Comments:**
> **username_0**: Thank you, Mats for providing clarity and outcome! I did use Dukt's Twitter example and could not figure out the error - the typo explains it....  

---

