I have a simple script in which I’d like to query Twitter for a string.

$tweets = $connection->get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=kvsc881fm&count=10”);

The above code works just fine.

$tweets = $connection->get(“https://api.twitter.com/1.1/search/tweets.json?q=#kvscrequest”);

This line produces no results.

What am I doing wrong?

Make sure that you encode the “#” character in your search query – if you don’t encode it, everything after it will not be considered by the server. You want your querystring to be more like “?q=%23kvcsrequest”

I’ve tried that, as well. I’ve tried removing it and just searching for a string.

Nothing seems to work! :frowning:

Here is the code I’m using:

<?php require_once("twitteroauth/twitteroauth.php"); $twitteruser = "kvsc881fm"; $numtweets = 5; $consumerkey = "X"; $consumersecret = "X"; $accesstoken = "X"; $accesstokensecret = "X"; $connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); #$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$numtweets); $tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=%23kvscrequest"); foreach($tweets as $tweet) { echo "

".$tweet->text."

"; } ?>

The line that is remarked out, works fine. The line that follows, does not. I’m thoroughly confused!

By “not working” do you mean that you get an error or just that you get an empty result set?

This particular hashtag would return 0 results at this time, as there aren’t any tweets within the last week with the hashtag indexed by the search service (the search API only goes back about one week).

Not Working = No results appear.

Didn’t know that about results, but I tried tweeting and changing the code as well to result_type=mixed with the same results:

$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?result_type=mixed&q=%23TheWalkingDead");

Anyone have any ideas on why this is producing no results?

@episod Any thoughts?

I have also the same problem. Could you find the solution?