Beacon Registered, but response indicates wrong UI

2019-03-06 03:30发布

问题:

I successfully registered a beacon using Google Proximity API but the response indicates a different UID

Request URL https://proximitybeacon.googleapis.com/v1beta1/beacons:register

Request

{
    "advertisedId": {
        "type": "EDDYSTONE",
        "id": "0x2f234454f4911ba9ffb6"
    },
    "status": "ACTIVE",
    "latLng": {
        "latitude": 51.4935657,
        "longitude": -0.1465538
    }
}

Response

{
  "beaconName": "beacons/3!d31d9fdb7e38e787f8f75d5b6bd7df6f",
  "advertisedId": {
    "type": "EDDYSTONE",
    "id": "0x2f234454f4911ba9ffbw=="
  },
  "status": "ACTIVE",
  "latLng": {
    "latitude": 51.4935657,
    "longitude": -0.14655379999999998
  }
}

If you notice carefully, the UID in the response does not match with the UID in POST request. Also, I tried the https://proximitybeacon.googleapis.com/v1beta1/beacons?q=status:active GET and I am still seeing slightly different UID.

回答1:

I'm assuming the strings you have in your code above are not actually what's being sent around because they shouldn't work at all.

There is an issue where: if you base64 encode the hex representation of the beaconID, and NOT the binary representation. It looks as though the server would erroneously accept this, but interpret it differently. That will be fixed soon.

So, instead of doing this:

var b64id = Base64Encode("abcdef0123456789abcdef0123456789");

You want to be doing:

var b64id = Base64Encode(HexToBinary("abcdef0123456789abcdef0123456789"));

I.e.

if you have the hex string for the id: abcdef0123456789abcdef0123456789, make sure that your code produces the base64 string: q83vASNFZ4mrze8BI0VniQ== — that is what you should be sending the server in the "id" field.

A BeaconID is 16 bytes long, that will show up as a 32 character hex string. The resulting base64 string encoding that beaconID should be about 23-24 characters long.

Hope that helps.