Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Net::Google::WebmasterTools: GWMT error: 404 Not Found

by Frosch (Initiate)
on Jul 22, 2016 at 10:09 UTC ( [id://1168340]=perlquestion: print w/replies, xml ) Need Help??

Frosch has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

when trying to use Net::Google::WebmasterTools I am getting the following error:

https://www.googleapis.com/webmasters/v3/sites/https://www.mySite.com/ +searchAnalytics/query GWMT error: 404 Not Found Not Found at ./Google_Search_Console_API.pl +line 43, <DATA> line 2231.
Here the used script (the credentials in this example like $client_id, $client_secret and $refresh_token have been certainly substituted by my own credentials).
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::Google::WebmasterTools; use Net::Google::WebmasterTools::OAuth2; # Insert your website URL here. my $site_url = "https://www.mySite.com"; # See GETTING STARTED for how to get a client id, client secret, and # refresh token my $client_id = "123456789012.apps.googleusercontent.com"; my $client_secret = "rAnDoMsEcReTrAnDoMsEcReT"; my $refresh_token = "RaNdOmSeCrEtRaNdOmSeCrEt"; my $wmt = Net::Google::WebmasterTools->new; # Authenticate my $oauth = Net::Google::WebmasterTools::OAuth2->new( client_id => $client_id, client_secret => $client_secret, ); my $token = $oauth->refresh_access_token($refresh_token); $wmt->token($token); # Build request my $req = $wmt->new_request( site_url => "$site_url", report_name => "searchAnalytics", method => "query", dimensions => ['country','device'], search_type => 'web', start_date => "2016-07-01", end_date => "2016-07-20", row_limit => 1000, ); # Send request my $res = $wmt->retrieve($req); die("GWMT error: " . $res->error_message) if !$res->is_success; # Print results print "Results: 1 - ", $res->items_per_page, " of ", $res->total_results, "\n\n"; for my $row (@{ $res->rows }) { print $row->get_source, ": ", $row->get_visits, " visits, ", $row->get_bounces, " bounces\n"; } print "\nTotal: ", $res->totals("visits"), " visits, ", $res->totals("bounces"), " bounces\n";

Any ideas what might be wrong?

Best regards, Frosch

Replies are listed 'Best First'.
Re: Net::Google::WebmasterTools: GWMT error: 404 Not Found
by Corion (Patriarch) on Jul 22, 2016 at 10:16 UTC

    Point 2 of this bug report seems to indicate that the queried site should be passed in URL-encoded. So maybe try with (roughly, untested) the following transformation:

    use URL::Encode; $site_url = url_encode($site_url); my $req = $wmt->new_request( ... )

      Thanks Corion, for your effort.

      With URL::Encode I am getting this error now:

      Undefined subroutine &main::url_encode called at ./Google_Search_Conso +le_API.pl line 12, <DATA> line 2231.

        Sorry - it seems you need to explicitly import url_encode:

        use URL::Encode 'url_encode';

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1168340]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found