BrenAtMogul
BrenAtMogul

Reputation: 31

PHP - Use Twitter API 1.1 to search for hashtags

I'm trying to find a way to use the main Twitter API to search tweets using PHP. The latest 1.1 documentation says this should be possible. I DO NOT want to use the http://search.twitter.com API.

I've set up a Twitter application and use the consumer, secret etc. keys to connect to it via Abraham's twitteroauth (https://github.com/abraham/). I can pull out my own timeline and my own bio info from Twitter using this method, but when I try to use the search it fails saying "Query parameters are missing".

I'm using the following code in a slightly modified test.php from that Git repository:

$parameters = array('q' => 'qwerty');
twitteroauth_row('search/tweets', $connection->get('search/tweets'), $connection->http_code,$parameters);

/* users/search */
$parameters = array('q' => 'brenmurrell');
twitteroauth_row('users/search', $connection->get('users/search', $parameters), $connection->http_code, $parameters);

/* statuses/public_timeline */
twitteroauth_row('statuses/user_timeline', $connection->get('statuses/user_timeline'), $connection->http_code,'q=twitpic');

The last two calls work as expected, the first does not. I get a 400 HTTP Error, with the specific API error code of 25 (Query paramaters are missing).

Am I missing something? Can anyone help with where this might be going wrong, or if this is genuinely broken functionality?

Upvotes: 3

Views: 6872

Answers (2)

Shashank Saxena
Shashank Saxena

Reputation: 2028

https://api.twitter.com/1.1/search/tweets.json?q=shrmi14

is the one that i used.

Incase you feel issues. refer https://dev.twitter.com/console for generating your own queries..

Upvotes: 0

veerman
veerman

Reputation: 103

I have the exact same problem ("Query parameters are missing") using search/tweets.json API 1.1 (and tmhOAuth php lib for oauth).

API docs: https://dev.twitter.com/docs/api/1.1/get/search/tweets

Edit: I fixed my issue.

tmhOAuth was removing my querystring params (even though it was a GET request). The params needed to be sent alongside in an array.

tmhOAuth before

$code = $twitter->request(
    'GET',
    $twitter->url('1.1/search/tweets.json?q=test')
);

tmhOAuth after (working)

$code = $twitter->request(
    'GET',
    $twitter->url('1.1/search/tweets.json'),
    array(
        'q' => 'test'     
    )
);

Upvotes: 2

Related Questions