我正在尝试使用数据集api PUT请求更新mapbox数据集中的要素数据。我正在关注他们Documentation,但它总是向我显示“未找到”响应消息。下面是我在laravel函数中使用的代码。我已经使用api get请求成功检索了相同feature_id和dataset_id的数据,但PUT请求不起作用。所以凭证没有错。
$userName = 'account_user_name';
$datasetId = 'dataset_id';
$featureId = 'feature_id';
$accessToken = 'access_token';
$featureBody = json_encode(array(
'id' => '{feature_id}',
'type' => 'Feature',
'geometry' => [
'type' =>'point',
'coordinates' => [ -1.16991, 52.964993]
],
'properties' => [
'id' => 10392,
'name' => 'Sharif & Sons Superstore 123',
'is_featured' => 'No'
]
));
$url = "https://api.mapbox.com/datasets/v1/{$userName}/{$datasetId}/features/{$featureId}?access_token=$accessToken";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Content-Length: ' . strlen($featureBody))
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS,$featureBody);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$json = curl_exec($ch);
curl_close($ch);
$arr1 = json_decode($json);
print_r($arr1);
答案 0 :(得分:0)
json对象id不应该是变量$ featureId,而不是字符串' {featureId}'?
$featureBody = json_encode(array(
'id' => $featureId,
'type' => 'Feature',
'geometry' => [
'type' =>'point',
'coordinates' => [ -1.16991, 52.964993]
],
'properties' => [
'id' => 10392,
'name' => 'Sharif & Sons Superstore 123',
'is_featured' => 'No'
]
));