【发布时间】:2017-04-24 23:59:32
【问题描述】:
我正在尝试通过 Laravel 5.3 中的 cURL 与 Google 进行通信。 我得到一个空的响应,但是一个 200 状态码。 这是我的代码:
public function directionGet($origin, $destination) {
$callToGoogle = curl_init();
$googleApiKey = '**************************';
curl_setopt_array(
$callToGoogle,
array (
CURLOPT_URL => 'http://maps.googleapis.com/maps/api/directions/json?origin='. $origin.'&destination=' . $destination . '&key= ' . $googleApiKey,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => 0
)
);
$response = curl_exec($callToGoogle);
curl_close($callToGoogle);
return response()->json($response);
}
【问题讨论】:
-
您确定您的 google map api 密钥也已在您的 google dev 仪表板中配置吗? developers.google.com/books/docs/v1/using
-
我可以推荐使用 guzzle 非常易于使用和阅读;)