Google Proximity Beacon API提供403个未经授权的错误

时间:2016-09-12 13:53:34

标签: android ibeacon iot eddystone proximityapi

我正在尝试使用谷歌的Beacon Proximity api。我已按照以下步骤进行整合:

1) Signed up on Google Api Console.
2) Created new Project.
3) enabled Beacon proximity api and Nearby Api.
4) Generated Api key from Credentials. 

之后我调用以下api:

 {
  "advertisedId": {
    "type": "EDDYSTONE",
    "id": "ABEiM0RVZneImaq7zN3u/w=="
  },
  "status": "ACTIVE",
  "placeId": "ChIJL_P_CXMEDTkRw0ZdG-0GVvw",
  "latLng": {
    "latitude": "71.6693771",
    "longitude": "-22.1966037"
  },
  "indoorLevel": {
    "name": "1"
  },
  "expectedStability": "STABLE",
  "description": "An example beacon.",
  "properties": {
    "position": "entryway"
  }
}

使用以下网址:

https://proximitybeacon.googleapis.com/v1beta1/beacons:register?key=xxxx(my_api_key)

但回复说:

{
  "error": {
    "code": 403,
    "message": "Unauthorized.",
    "status": "PERMISSION_DENIED"
  }
}

我错过了什么..

I also tried to use Beacon tools app but after entering EID and all other credentials..the App crashes(on android), while it is not able to connect to my eddystone on Ios. 

2 个答案:

答案 0 :(得分:1)

找到解决方案,API_KEY只能用于访问已注册的信标及其特性,而注册和更新我们需要ClientId和客户端密钥,您可以在OAuth2.0 Playground中注册它。 它对我有用;)

答案 1 :(得分:0)

您可以在google API控制台上创建帐户服务密钥后获取服务令牌。然后使用以下代码生成它:

String token = null;

try{
    GoogleCredential credential = GoogleCredential.fromStream(accesKey).createScoped
                    (Collections.singleton("https://www.googleapis.com/auth/userlocation.beacon.registry"));


    credential.refreshToken();
    token = credential.getAccessToken();

} catch (FileNotFoundException ex) {
        Logger.getLogger(BeaconRegisterClass.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
        Logger.getLogger(BeaconRegisterClass.class.getName()).log(Level.SEVERE, null, ex);
}

然后将其放在通话的标题上:

key: Authorization value: Bearer (your token here)

将此调用的主体设置为beacon.json