REST::Google - access Google REST (aka AJAX) API from Perl


        use REST::Google;

        # set service to use

        # provide a valid http referer

        my $res = REST::Google->new(
                q => 'Larry Wall',

        die "response status failure" if $res->responseStatus != 200;

        my $data = $res->responseData;

        use Data::Dumper;
        print Dumper( $data );


REST::Google provides OO interface to Google REST (aka AJAX) API.

Note that this module provides low-level access to Google services API. Consider using REST::Google::Search, REST::Google::Translate or REST::Google::Feeds, which provide convenient access to service request results.



Get/set service to use. You must set this to valid URL. E.g.:


Normally, you don't need this, since REST::Google::Search, REST::Google::Translate or REST::Google::Feeds modules do this for you.


Get/set HTTP Referer header.


Note: Google says that you should supply a valid HTTP referer header each time you perform a request to their AJAX API, so new() raises warning unless referer is specified.


The constructor use it's arguments to build a valid HTTP GET request to given service, so it takes the same arguments as the given web service takes. Please refer to 'Google AJAX API' documentation for complete list of arguments for a service you're using. E.g.:

        my $res = REST::Google->new(
                q => 'Pamela Anderson',

For example, if you're using the Web search service, the code above will perform a following HTTP GET request:

Note: You can left protocol version number unspecified since v=1.0 is passed by default.

For service specific arguments, check Google API documentation pages in the SEE ALSO section.

REST::Google object completely represents Google API response objects and has the following structure:

                "responseData" => {},
                "responseDetails" => undef | string-on-error,
                "responseStatus" => 200 | error-code

The responseStatus property contains a value of 200 on success and a non-200 HTTP error status code on failure. If there is a failure, responseDetails contains a diagnostic string.


Contain an error string if responseStatus is not 200.


Returns a responseData structure. Please refer to service API documentation for response structure details.


REST::Google uses JSON::Any for decoding Google AJAX Search API response and LWP for search request sending.


REST::Google::Search, REST::Google::Translate, REST::Google::Feeds child classes for Search, Translate and Feeds services correspondingly. - this project on github; - brief information about Google Search AJAX API in non-Javascript environments; - Google Search AJAX API documentation; - Google Translate AJAX API documentation; - Google Feeds AJAX API documentation;


Copyright 2008, Eugen Sobchenko <> and Sergey Sinkovskiy <>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.