Script is getting 403 Forbidden using Custom Search API

Skip to first unread message


Dec 8, 2013, 11:27:20 AM12/8/13

I am trying to search Google using Custom Search API with the following Perl script. Strangely, the response with the script is [403 Forbidden] while
the same request over the GUI (Google APIs Explorer/CustomSearch API/search.cse.list) pass through.

Here is the script:


use strict;
use warnings;
use WWW::Google::CustomSearch;
use Data::Dumper;

my $api_key = '{HERE_IS_MY_API_KEY}';
my $cx      = '{MY_custom_search_engine_ID}';
my $filter  = '0';
my $country = 'de';
my $engine  = WWW::Google::CustomSearch->new(cx => $cx, filter => $filter, gl => $country, api_key => $api_key);
#print Dumper(\$engine);
my $result  = $engine->search('Linux');
print Dumper(\$result);
my $page    = $result->request;
my $another = $page->fetch; 

Comparing both search strings (search.cse.list and the one generated by my script) are almost the same (apart from some additional parameters which
are not relevant). The search strings are:


My Perl Script:

Any ideas what might be wrong and how to fix it?

Best Regards,


Peter Gransee

Apr 2, 2016, 8:34:43 AM4/2/16
to Google AJAX APIs
I had the same problem- for me I had to enable the API in the google API manager.{your project - create this in the control panel for google custom search}

So even though I had a custom search engine id and a API key, the API was not enabled for some reason. Once I enabled it, the error 403 went away almost immediately.

Another possibility I found while searching for the solution is that you have IP blocking turned on in the API configuration (although this was not the case for me).


Eugène van der Merwe

Apr 16, 2019, 7:19:36 AM4/16/19
to Google AJAX APIs
@Peter Gransee,

Sir, you are a scholar and a gentleman. I created a Custom Search Engine a few days ago and I've been humbly using it to see various results. Small hits. Then all of a sudden a 403! I followed your advice, got myself a an API enabled, and voila! As you say, straight away the problem is gone.

Love it!

warm regards,
Reply all
Reply to author
0 new messages