How to search and print tweets from twitter?

i have attached my code its working and giving results for user time and printing tweets when i pass the arguments through the command line.

for searching am not printing   "print_r($tweets);"  this giving the result.

for ($i = 0; $i <$notweets; $i++) {
            echo ($tweets[$i]['text']) . "\n";
        }
   when i try to print this its giving me blanks..
can any one know how to solve this

Thanks
vishnu kalakotaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
This is a data-dependent problem, so we will need to see the data.  Please use var_dump($tweets) and post the output here in the code snippet.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Also, please dump out the value of $notweets and post it here, too.  Thanks.
0
vishnu kalakotaAuthor Commented:
Hi Ray Thank for your answer

var_dump($notweets) results --------->   string(2) "10"
var_dump($tweets) results ----------> big array

i have attached my code and can you help me where am going wrong





<?php
require_once('TwitterAPIExchange.php');
$task = $argv[1];
switch ($task) {
    case "show":
       
        $twitteruser = $argv[2];
        //$twitterkeyword = $argv[2];
        $notweets    = $argv[3];
       
        $settings = array(
            'oauth_access_token' => "XXXXXXXXXXXXX",
            'oauth_access_token_secret' => "XXXXXXXXXXXXX",
            'consumer_key' => "XXXXXXXXXXXXX",
            'consumer_secret' => "XXXXXXXXXXXXX"
        );
       
        $url           = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
        $getfield      = '?include_entities=false&include_rts=true&screen_name=' . $twitteruser . '&scount=' . $notweets;
        $requestMethod = 'GET';
       
        $twitter = new TwitterAPIExchange($settings);
        $result  = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
        $tweets  = json_decode($result, true);
        //print_r($tweets);
        for ($i = 0; $i <= $notweets; $i++) {
            echo ($tweets[$i]['text']) . "\n";
        }
        break;
    case "search":
        $query         = $argv[2];
        //$twitterkeyword = $argv[2];
        $notweets      = $argv[3];
        $settings      = array(
            'oauth_access_token' => "XXXXXXXXXXXXX",
            'oauth_access_token_secret' => "XXXXXXXXXXXXX",
            'consumer_key' => "XXXXXXXXXXXXX",
            'consumer_secret' => "XXXXXXXXXXXXX"
        );
        $url           = 'https://api.twitter.com/1.1/search/tweets.json';
        $getfield      = '?include_entities=false&include_rts=true&q='.$query.'&result_type=recent&scount='.$notweets.'&lang=en';
        $requestMethod = 'GET';
        $twitter       = new TwitterAPIExchange($settings);
        $result        = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
        //print_r($result);
        $tweets = json_decode($result,true);
        print_r($tweets);
       for ($i = 0; $i <$notweets; $i++) {
            echo ($tweets[$i]['text']) . "\n";
        }
        break;
}

?>
0
Ray PaseurCommented:
Sorry, the code can't help me.  I need to see the data to be able to help you.  I already knew it was a big array :-)

Maybe you can dial back the $notweets variable to shrink the array.
0
vishnu kalakotaAuthor Commented:
Thnak you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.