0

I want to get timeZoneId using googleapis url. I want this url return me json response to parse it later and insert lat and long in my database. It works fine when it's not a googlemap url but i have the famous "request_denied" error when I use this kind of url in my code:

How to get json in url from google, I want to get timezone from latitude, longitude, and timestamp

https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&sensor=false

I have tried get data from URL with file_get_contents.

$json_url = 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&sensor=false';
$json = file_get_contents($json_url);
$obj = json_decode($json);
echo $obj->timeZoneId;

But it doesn't work. It alwy return "status" : "REQUEST_DENIED" Thanks any got a tip.

Update

thank for all :) i checked in php extention-> php_openssl and it work

HoangHieu
  • 2,802
  • 3
  • 28
  • 44

3 Answers3

2

You forgot the s in the url:

$json_url = 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&sensor=false';
$json = file_get_contents($json_url);
$obj = json_decode($json);
echo $obj->timeZoneId;

This works on my PC.

koesie10
  • 572
  • 4
  • 17
1
    $json_url = 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&sensor=false'; 

    $json = file_get_contents($json_url);
    $data = json_decode($json, TRUE);
    echo $data['timeZoneId'];

Try this i think this might help. The problem is with json_decode.

iraycd
  • 892
  • 1
  • 8
  • 23
1

Change your url from:

$json_url = 'http://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&sensor=false';

to this:

$json_url = 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&sensor=false';

With http you are getting REQUEST_DENIED.

Luigi Siri
  • 2,068
  • 2
  • 19
  • 27