Reputation: 1002
I am trying to consume Google's Beacon Proximity api. i have followed following steps to integrate them:
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.
Afterwards i invoke the following 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"
}
}
with the follwing url:
https://proximitybeacon.googleapis.com/v1beta1/beacons:register?key=xxxx(my_api_key)
but the response says:
{
"error": {
"code": 403,
"message": "Unauthorized.",
"status": "PERMISSION_DENIED"
}
}
what is it that i am missing..
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.
Upvotes: 0
Views: 599
Reputation: 381
You can Get a service token after creating an account service key on the google API Console. Then generate it with this code:
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);
}
Then put it on the header of your call:
key: Authorization value: Bearer (your token here)
set the body of this call as beacon.json
Upvotes: 0
Reputation: 1002
Found the Solution, API_KEY can be used only to Access already registered beacons and their Characteristics, while to Register and update we require ClientId and client Secret key and you can register it in OAuth2.0 Playground. it worked for me ;)
Upvotes: 1