Google 为 C# 客户端添加 API 返回 Invalid_Request
Google Place Add API Returning Invalid_Request for C# client
这是我的 C# 代码:
private async Task<AddPlaceResponse> AddLocation(Place place)
{
AddPlaceResponse resp = new AddPlaceResponse();
try
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpContent contentPost = new StringContent(JsonConvert.SerializeObject(place), Encoding.UTF8, "application/json");
string url = string.Format("https://maps.googleapis.com/maps/api/place/add/json?key=MYKEY");
HttpResponseMessage response = await client.PostAsync(url, contentPost);
if (response.IsSuccessStatusCode)
{
var data =response.Content.ReadAsStringAsync();
var status = data.Result;
resp = JsonConvert.DeserializeObject<AddPlaceResponse>(status);
}
}
}
catch (Exception ex)
{
}
return resp;
}
这是请求Json(放置对象):
{"location":{"lat":"22.5674722","lng":"88.3086388"},"accuracy":50,"name":"Prabartak Sangha","phone_number":"(+91) 8909878909","address":"Sitanath Banerjee Lane","types":["shoe_store"],"website":"https://www.google.co.in","language":"en"}
我不明白为什么我的状态总是 "Invalid_Request"
。
请帮忙
请检查您的 HTTP POST 添加请求的请求正文。
所述
INVALID_REQUEST
generally indicates that the request contains missing parameters. It will also be returned when attempting to add a place whose name is greater than 255 characters.
如Add a place中给出的,请注意需要参数,但也有限制。
accuracy
address
-(推荐)
language
location
- (必填)
name
-(必需且限制为 255 个字符)
phone_number
-(推荐)
types
- (必填)
website
-(推荐)
更新
不幸的是,Place Add has been deprecated on June 30, 2017 and will stop working on June 30, 2018. So you cannot use this method anymore. For further details please refer to the corresponding geo blog post。
这是我的 C# 代码:
private async Task<AddPlaceResponse> AddLocation(Place place)
{
AddPlaceResponse resp = new AddPlaceResponse();
try
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpContent contentPost = new StringContent(JsonConvert.SerializeObject(place), Encoding.UTF8, "application/json");
string url = string.Format("https://maps.googleapis.com/maps/api/place/add/json?key=MYKEY");
HttpResponseMessage response = await client.PostAsync(url, contentPost);
if (response.IsSuccessStatusCode)
{
var data =response.Content.ReadAsStringAsync();
var status = data.Result;
resp = JsonConvert.DeserializeObject<AddPlaceResponse>(status);
}
}
}
catch (Exception ex)
{
}
return resp;
}
这是请求Json(放置对象):
{"location":{"lat":"22.5674722","lng":"88.3086388"},"accuracy":50,"name":"Prabartak Sangha","phone_number":"(+91) 8909878909","address":"Sitanath Banerjee Lane","types":["shoe_store"],"website":"https://www.google.co.in","language":"en"}
我不明白为什么我的状态总是 "Invalid_Request"
。
请帮忙
请检查您的 HTTP POST 添加请求的请求正文。
所述
INVALID_REQUEST
generally indicates that the request contains missing parameters. It will also be returned when attempting to add a place whose name is greater than 255 characters.
如Add a place中给出的,请注意需要参数,但也有限制。
accuracy
address
-(推荐)language
location
- (必填)name
-(必需且限制为 255 个字符)phone_number
-(推荐)types
- (必填)website
-(推荐)
更新
不幸的是,Place Add has been deprecated on June 30, 2017 and will stop working on June 30, 2018. So you cannot use this method anymore. For further details please refer to the corresponding geo blog post。