尝试使用以下代码向Google发送API请求API:
<?php
include_once 'configuration.php';
$data = array('query' => 'restaurants in Sydney', 'key' => API_KEY);
$url = 'https://maps.googleapis.com/maps/api/place/textsearch/json';
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'GET',
'content' => http_build_query($data)
)
);
//print_r($options);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
但我收到错误
警告: file_get_contents(https://maps.googleapis.com/maps/api/place/textsearch/json):无法打开流:HTTP请求失败! HTTP / 1.0 400错误请求 在第18行的index.php中布尔(假)
有什么问题?