有人可以帮我弄这个吗。我是 Eddystone Beacon 的新手,这是我第一次使用 Google Cloud API(Proximity beacon api)。我正在尝试通过 Proximity Beacon API 向我注册的一个信标(可以在谷歌信标仪表板中完成)添加附近通知,并想知道为什么我会收到此错误:
{ "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"{\"attachmentName\":\"beacon_eddystone\",\"data\":\"eyJ0aXRsZSI6IlNJTSBUZXN0IiwidXJsIjoiaHR0cDpcL1wvd3d3LnN1cmlnYW9pbnRlcm5ldG1hcmtldGluZy5jb20ifQ\": Cannot bind query parameter. Field '{\"attachmentName\":\"beacon_eddystone\",\"data\":\"eyJ0aXRsZSI6IlNJTSBUZXN0IiwidXJsIjoiaHR0cDpcL1wvd3d3LnN1cmlnYW9pbnRlcm5ldG1hcmtldGluZy5jb20ifQ' could not be found in request message.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest","fieldViolations": [ { "description": "Invalid JSON payload received. Unknown name \"{\"attachmentName\":\"beacon_eddystone\",\"data\":\"eyJ0aXRsZSI6IlNJTSBUZXN0IiwidXJsIjoiaHR0cDpcL1wvd3d3LnN1cmlnYW9pbnRlcm5ldG1hcmtldGluZy5jb20ifQ\": Cannot bind query parameter. Field '{\"attachmentName\":\"beacon_eddystone\",\"data\":\"eyJ0aXRsZSI6IlNJTSBUZXN0IiwidXJsIjoiaHR0cDpcL1wvd3d3LnN1cmlnYW9pbnRlcm5ldG1hcmtldGluZy5jb20ifQ' could not be found in request message." } ] } ] } }
我在php中使用cURL创建了一个HttpRequest,代码如下:
$array = array();
$array['title'] = "SIM Test";
$array['url'] = "http://www.surigaointernetmarketing.com";
$data = base64_encode(json_encode($array));
//echo $data;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://proximitybeacon.googleapis.com/v1beta1/beacons/<my-beacon-name>/attachments?projectId=<my-project-id>',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION =>
CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{"attachmentName":"beacon_eddystone","data":"'.$data.'","namespacedType":"com.google.nearby/en"}',
CURLOPT_HTTPHEADER => array( "authorization: Bearer <my-bearer-token>" ),));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err)
echo "cURL Error #:" . $err;
else
echo $response;
我从这里得到了代码。并按照 Proximity Beacon REST API 入门中的说明进行操作。http请求体(CURLOPT_POSTFIELDS)一定有错误。我不知道为什么,请帮忙。