当前位置: 动力学知识库 > 问答 > 编程问答 >

php - how to get json in url https

问题描述:

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 = 'http://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

网友答案:

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.

网友答案:
    $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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: