403 error with google geolocation api in c# -


i trying use google maps geolocation api (https://developers.google.com/maps/documentation/geolocation/intro) in c# (.net 4.6.1). have setup server key , enabled google maps geolocation api in api manager. here code:

using (httpclient client = new httpclient()) {     client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json"));     var response = await client.postasjsonasync("https://www.googleapis.com/geolocation/v1/geolocate", new { key = "keyvalue" });     return await response.content.readasstringasync(); } 

i 403 error. here complete response:

{ "error": {     "errors": [{         "domain": "usagelimits",         "reason": "dailylimitexceededunreg",         "message": "daily limit unauthenticated use exceeded. continued use requires signup.",         "extendedhelp": "https://code.google.com/apis/console"     }],     "code": 403,     "message": "daily limit unauthenticated use exceeded. continued use requires signup." } 

}

i know key value correct , know have enabled api. know haven't reached daily limit, because google console lists usage 0 day. see issue code or have other suggestions? must incorrectly sending key, don't know error in code.

update

the correct code is:

using (httpclient client = new httpclient()) {     client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json"));     var response = await client.postasjsonasync("https://www.googleapis.com/geolocation/v1/geolocate?key=keyvalue", "" );     //or client.postasync used way:     //var response = await client.postasync("https://www.googleapis.com/geolocation/v1/geolocate?key=keyvalue", new stringcontent("", encoding.utf8, "application/json"));     return await response.content.readasstringasync(); } 

i passing key json object instead of putting key in url.

you must add key parameter url

https://www.googleapis.com/geolocation/v1/geolocate?key=keyvalue 

Comments