A call like this

https://maps.googleapis.com/maps/api/timezone/json?location=30,30

as is done in _tzfield_geofield_get_timezone($lat, $lon)
requires a key.

the response has a nice errormessage, but no timezoneid,
and the function fails and fails to call the watchdog.

Notice: Undefined property: stdClass::$timeZoneId in _tzfield_geofield_get_timezone() (line 68 of /home/iaf/www/dev/site/sites/all/modules/tzfield/tzfield_geofield/tzfield_geofield.module).

Comments

commonpike created an issue. See original summary.

commonpike’s picture

StatusFileSize
new41.97 KB

.. and its expensive, too. $5 per 1000 requests.

mfb’s picture

Status: Active » Needs review
StatusFileSize
new1.24 KB

  • mfb committed 446205f on 7.x-1.x
    Issue #3008717 by mfb, commonpike: Google requires an api key
    
mfb’s picture

Status: Needs review » Fixed
mfb’s picture

I gave this a minimal fix as I do not use this module.

Please feel free to contribute further improvements / bug fixes :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

commonpike’s picture

Thanks for the patch - I see it is even committed.
Nevertheless

// To make API requests, you must set this API key variable.
      'key' => variable_get('tzfield_geofield_google_timezone_api_key'),

Where would anyone set that variable ? And how would people know
it has to be set, especially since there is no error in the watchdog

Would it make sense to have a settings page to enter your api key in ?
With a cog wheel appearing in the modules section ?

mfb’s picture

@commonpike yes that's still needed. You can add a patch in this issue and reopen it, or create a new issue.

There should be an error logged in watchdog. Are you not seeing an error?

commonpike’s picture

Yes, the error appears in the watchdog.

It's a bit uninformative. If you add $result->data, that looks nice

$msg = t('Google API returned bad status.\nStatus: @status', $args);
$msg .= ' '.$result->data;

will throw

Exception: Google API returned bad status. Status: REQUEST_DENIED { "error_message" : "You must enable Billing on the Google Cloud Project at https://console.cloud.google.com/project/_/billing/enable Learn more at https://developers.google.com/maps/gmp-get-started", "results" : [], "status" : "REQUEST_DENIED" } in geocoder_google() (line 123 of /xxxx/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc).

mfb’s picture

@commonpike I think you might be commenting on the wrong issue queue? This issue is re: tzfield_geofield module, not geocoder module.

Hopefully tzfield_geofield is correctly logging the error message; the relevant code is:

  watchdog('tzfield_geofield', 'Google time zone API error %status %error_message', array(
    '%status' => $json->status,
    '%error_message' => $json->errorMessage,
  ), WATCHDOG_ERROR);