Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Tweets from EpiTwitterJson
    text
    copied!<p>I've been banging my head against the wall for a few days now trying to do something that should be so simple. I am trying to use Jaison Mathai's EpiTwitter library to retrieve tweets from my account. Here is my code to get my tweets:</p> <pre><code>&lt;?php $twitterObj = new EpiTwitter($__TWITTER['ConsumerKey'], $__TWITTER['ConsumerSecret'],$__TWITTER['MyAccessToken'],$__TWITTER['MyAccessTokenSecret']); $twitterInfo= $twitterObj-&gt;get_accountVerify_credentials(); $twitterInfo-&gt;response; // ^ This part works fine, I can get my user info and profile pic and whatnot $username = $twitterInfo-&gt;screen_name; $tjson = $twitterObj-&gt;get('statuses/user_timeline.json', array("screen_name"=&gt;$username)); </code></pre> <p>As far as I can tell, ^ this also works as it should. If I var_dump($tjson), I can see the tweets that I want to access, among a HUGE mess of other data.</p> <p>My question boils down to this: from this point, how can i simply print out each tweet returned? Here's what I've tried so far:</p> <pre><code>foreach($tjson as $tweet) print($tweet) //^ Throws IllegalArgumentException, "Not an array or object" foreach($tjson-&gt;responseText as $tweet) print($tweet) //^ Warning: illegal argument. Doesn't print anything print_r($tjson-&gt;response) //Prints NULL </code></pre> <p>I thought $tjson->response would be what I want, because in the __get method in EpiTwitterJson, there is a line: <code>$this-&gt;response = json_decode($this-&gt;responseText, 1);</code>. Right after this line if I <code>var_dump($this-&gt;response)</code>, I get my tweets along with a little less data than var_dump($tjson) before. If on that same line I <code>print($this-&gt;response['status']['text'])</code>, I get a nice string of my tweet, which is exactly what I want. </p> <p>What I don't quite understand is why $this->response is set inside of the EpiTwitterJson class, but $tjson->response is NULL in my code. I've looked and looked and looked but I can't seem to find any code snippets to get tweets with this library specifically. I think it's just one of those things that must be so obvious and simple that my brain refuses to accept it. Obviously I could just crawl through $tjson->responseText, but I thought the whole point of the EpiTwitterJson class was so I would not have to do that? The <strong>ideal</strong> answer to my question will be code to boil down my $tjson object so i can say </p> <pre><code>foreach(something as $tweet) //do stuff with the tweet </code></pre> <p>Second best answer would be code to do this with another library. I only chose the EpiTwitter lib because it 'supports async' which sounds kinda cool if I ever decide to use it, and because it seemed like the simplest (ie least lines of code on my part). Quite frankly I really care more about making this work than understanding it; I can figure out what it all means later on.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload