Trying to use Abraham's twitteroauth library to make search query, returns list of numbers in scientific notation?

557 views
Skip to first unread message

Chris Sobolewski

unread,
Feb 28, 2011, 1:15:23 PM2/28/11
to Twitter Development Talk
I am attempting to use the twitteroauth library to make a query, and I
am getting some odd responses back.

My code:
$twitteroauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$q=urlencode("#twitter");
$query = $twitteroauth->get("search.json?q={$q}&rpp=100");
echo "<pre>";
$qq = $query;
print_r($qq);
echo "</pre>";

First odd result is, when I try doing a JSON decode, I get an error
that it is not JSON which is what I expected to get back.

Second odd result is when I print_r, this is what I recieve back:

stdClass Object
(
[created_in] => 0.11146
[statuses] => Array
(
[0] => 4.2285483207823E+16
[1] => 4.2285478212403E+16
[2] => 4.2285477021237E+16
[3] => 4.228546655225E+16
[4] => 4.2285444607648E+16
[5] => 4.2285433509528E+16
[6] => 4.2285433383559E+16
.... so on all the way down to 100
)
)

Abraham Williams

unread,
Feb 28, 2011, 2:03:47 PM2/28/11
to twitter-deve...@googlegroups.com
The Search API does not support authentication and so TwitterOAuth does not currently support it. TwitterOAuth uses https://api.twitter.com/1/ as the API URL when the Search API uses http://search.twitter.com as documented http://dev.twitter.com/doc/get/search.

To use the Search API I recommend performing a simple cURL request instead.

Also in general TwitterOAuth requests should formated like

   $query = $twitteroauth->get("search", array("q" => $q, "rpp" =>100)>;

instead of

   $query = $twitteroauth->get("search.json?q={$q}&rpp=100");

Finally the integers returned are larger then 32bit PHP supports. In officially supported Twitter API methods most id elements have a matching id_str element that is a string.

Abraham
-------------
Abraham Williams | Hacker Advocate | abrah.am
Just launched from Answerly: InboxQ for Chrome
@abraham | github.com/abraham | blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.




--
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: http://groups.google.com/group/twitter-development-talk

Chris Sobolewski

unread,
Feb 28, 2011, 2:10:35 PM2/28/11
to Twitter Development Talk
Thanks, I originally started out formatting the twitter query with an
array, as you suggest, the final result here is a product of trouble
shooting to get more than just an empty screen.

I will give this a try. Thank you.

On Feb 28, 2:03 pm, Abraham Williams <4bra...@gmail.com> wrote:
> The Search API does not support authentication and so TwitterOAuth does not
> currently support it. TwitterOAuth useshttps://api.twitter.com/1/as the
> API URL when the Search API useshttp://search.twitter.comas documentedhttp://dev.twitter.com/doc/get/search.
>
> To use the Search API I recommend performing a simple cURL request instead.
>
> Also in general TwitterOAuth requests should formated like
>
>    $query = $twitteroauth->get("search", array("q" => $q, "rpp" =>100)>;
>
> instead of
>
>    $query = $twitteroauth->get("search.json?q={$q}&rpp=100");
>
> Finally the integers returned are larger then 32bit PHP supports. In
> officially supported Twitter API methods most id elements have a matching
> id_str element that is a string.
>
> Abraham
> -------------
> Abraham Williams | Hacker Advocate | abrah.am
> <http://abrah.am>Just launched from Answerly <http://answerly.com>:
> InboxQ<http://inboxq.com>for Chrome
> @abraham <https://twitter.com/abraham> | github.com/abraham | blog.abrah.am
> This email is: [ ] shareable [x] ask first [ ] private.
>
> On Mon, Feb 28, 2011 at 10:15, Chris Sobolewski
> <sobolewski.ch...@gmail.com>wrote:

Peter Denton

unread,
Mar 2, 2011, 2:11:28 PM3/2/11
to twitter-deve...@googlegroups.com, Chris Sobolewski
I think the issue regarding this -- and I may be out of the loop on an update -- is that the end point of "http://api.twitter.com/1/search" is gone.

Thus, when you construct the url using Abraham's library, you get a url with http://api.twitter.com/1/search as the host instead of using http://search.twitter.com/search
Reply all
Reply to author
Forward
0 new messages