【发布时间】:2015-02-26 10:16:55
【问题描述】:
我正在使用Google Tracks API 构建一个简单的基于网络的程序来跟踪具有发送纬度和经度坐标的跟踪设备的车辆。 我正在使用 PHP 和 OAuth2 PHP library 进行授权连接。
授权并获得访问令牌后,我正在请求创建实体。尽管我似乎无法使其正常工作并不断收到“400 Bad Request”响应。遵循documentation 中显示的所有步骤。
这是我的代码:
$url = 'https://www.googleapis.com/tracks/v1/entities/create/?access_token='.$parsedAuth['access_token'];
$data = array('entities' => array( "name"=> "Chevrolet" ));
$json_data = json_encode($data);
$data_length = http_build_query($data);
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n". "Content-Length: " . strlen($data_length) . "\r\n",
'method' => 'POST',
'content' => $json_data
),
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
var_dump($response);
确切的错误是:“无法打开流:HTTP 请求失败!HTTP/1.0 400 错误请求”
为什么我收到一个错误的请求?什么是注册这些实体并返回 ID 的好请求? 谢谢
【问题讨论】:
标签: php google-maps google-geocoding-api