谷歌的地方操作删除的地方给无效请求 [英] google place action delete places gives invalid request

查看:170
本文介绍了谷歌的地方操作删除的地方给无效请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用谷歌的地方api.I我能够添加从我的应用程序的新的地方,当我试图删除它显示在附近搜索result.Now被搜索添加和删除在靠近谷歌地图的地方创建一个Android应用程序任何地方使用删除操作这个地方,它总是给 INVALID_REQUEST 响应。

I am creating an android application for adding and deleting places on google map near by search using google places api.I am able to add new places from my application which is displayed in nearby search result.Now when i am trying to delete any of this place using place delete action,it always gives INVALID_REQUEST response.

下面是我的网址删除地方:

Here is my url for deleting places:

String url="https://maps.googleapis.com/maps/api/place/delete/json?key=MY BROWSER KEY";
new delete().execute(url);

和我的code删除的地方是:

And my code for deleting place is:

public class delete extends AsyncTask<String, Void, String>{



       @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(UserBuisness.this);
            pDialog.setMessage("deleting..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }


        @Override
    protected String doInBackground(String... url) {
        // TODO Auto-generated method stub
        StringBuilder placesRemover = new StringBuilder();
        for (String placeDeleteURL : url) {




         HttpClient httpclientdelete = new DefaultHttpClient();


         HttpPost httpPostDelete = new HttpPost(placeDeleteURL);
         InputStream inputStream = null;



      try {
          JSONObject json=new JSONObject();
          try {

              //place_id contains place_id of place to be deleted

            json.put("placeid",place_id);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }





          String postBodyDelete=json.toString();    

          StringEntity se = new StringEntity(postBodyDelete,HTTP.UTF_8);
          httpPostDelete.setEntity(se);
          HttpResponse httpResponse = httpclientdelete.execute(httpPostDelete);
         inputStream = httpResponse.getEntity().getContent();
         if(inputStream != null){
             InputStreamReader placesInputDelete = new InputStreamReader(inputStream);
                //use buffered reader to process
                BufferedReader placesRemoverReader = new BufferedReader(placesInputDelete);
                //read a line at a time, append to string builder
                String lineIn;
                while ((lineIn = placesRemoverReader.readLine()) != null) {
                    placesRemover.append(lineIn);
                }
         }



      } catch (UnsupportedEncodingException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     } catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
        }

        return placesRemover.toString();
    }

    protected void onPostExecute(String result) {
        JSONObject response=null;
        String sam="";
         try {
            response=new JSONObject(result);
            sam=response.getString("status");



        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         pDialog.dismiss();

            Toast.makeText(getApplicationContext(), sam, 1000).show();


    }



}

我没有得到对于 INVALID_REQUEST 由于的URL,后机身相同的格式为删除places.Any怎样的帮助要求谷歌地方行动AP preciated的原因

I am not getting the reason for INVALID_REQUEST since the url,and post body is of the same format as required by google place action for deleting places.Any kind of help is appreciated.

推荐答案

我只是遇到了这个同样的问题,想通了这是谷歌的文档中的错误。对于删除位置明确表示(在两个地方),该文档JSON关键对于地方ID是placeid。

I just ran into this same problem and figured out it's an error in Google's documentation. The documentation for deleting a place clearly says (in two places) that the JSON key for the place id is "placeid".

POST https://maps.googleapis.com/maps/api/place/delete/json?key=AddYourOwnKeyHere HTTP/1.1
Host: maps.googleapis.com

{
  "placeid": "place ID"
}

...

placeid: A string identifying the place that must be deleted, returned from a place search.

正确的关键,虽然实际上是的 place_id 的,这是与其它API调用一致。

The correct key though is actually "place_id", which is consistent with the other API calls.

因此​​,在你的情况,你只需要更新该行:

Therefore, in your case you just need to update this line:

json.put("placeid",place_id);

是这样的:

json.put("place_id",place_id);

我知道这是一个迟到的答案,但我希望这可以帮助仍然!我也开了与谷歌的企业支持票,以确保此错误的文档中得到解决。

I know this is a late answer, but I hope this still helps! I also opened a ticket with Google enterprise support to ensure this error in the documentation is resolved.

这篇关于谷歌的地方操作删除的地方给无效请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆