android – URL类呈现 – 带有next_page_token的Invalid_Request

前端之家收集整理的这篇文章主要介绍了android – URL类呈现 – 带有next_page_token的Invalid_Request前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在我的Android应用程序中,用户可以选择他想要查看的地方的类别(咖啡馆,餐馆……).

当我使用以下网址时,我从google-places-api获得带有next_page_token的结果:

https://maps.googleapis.com/maps/api/place/textsearch/json?query=cafe+in+Elfde-Liniestraat%2C+Hasselt%2C+Belgium&pagetoken=ClRHAAAAqYa7IpwMQH3q1DyinfsMnkuOaZg8wQrp0pvzarv13pwqruqT2YfaEry6v_d-L4d_TC13G6iHuPz-rc1KbI6XRE01rB5CuXcHISu-CI_CaKESEMUxSjHhHDNee4xbr2tPEZcaFPvO6xlRDjs-5AixyD9vamWwTGlU&sensor=true&key=

或者这个网址:

https://maps.googleapis.com/maps/api/place/textsearch/json?pagetoken=ClRHAAAAqYa7IpwMQH3q1DyinfsMnkuOaZg8wQrp0pvzarv13pwqruqT2YfaEry6v_d-L4d_TC13G6iHuPz-rc1KbI6XRE01rB5CuXcHISu-CI_CaKESEMUxSjHhHDNee4xbr2tPEZcaFPvO6xlRDjs-5AixyD9vamWwTGlU&sensor=true&key=

我收到了INVALID_REQUEST.

这是我用来运行和获取结果的代码

@Override
    protected ArrayList

这是logcat的输出

11-03 14:47:13.832: D/URL OUTPUT(19532): {   "html_attributions" : [],"next_page_token" : "ClRHAAAAqYa7IpwMQH3q1DyinfsMnkuOaZg8wQrp0pvzarv13pwqruqT2YfaEry6v_d-L4d_TC13G6iHuPz-rc1KbI6XRE01rB5CuXcHISu-CI_CaKESEMUxSjHhHDNee4xbr2tPEZcaFPvO6xlRDjs-5AixyD9vamWwTGlU","results" : [      {         "formatted_address" : "Meldertstraat 42,Hasselt,België","geometry" : {            "location" : {               "lat" : 50.9311660,"lng" : 5.3423240            }         },"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png","id" : "e6ba73e5b439dddb83aaefc94c71954da0cb0268","name" : "Café Café","rating" : 4.40,"reference" : "CnRpAAAAdVZpUI4NKwsAiQTOjbYG9psNbU7awZkS6_8Ee4r3AvCKhpqWeiDqdof7zYmoUZWKj0A8rOwtncSa1YFVNNo6RxFmmHvuNdWCaucTqkuSSDw8E2o0pf5E6EiMj-7-Hd5xBzDtC0j9d5lLcVWW3AQy1xIQRwgfWwrZkyK65blCeGqhFhoUB9kTW5QVD9sNNuF75MvVewYTcxA","types" : [ "cafe","food","establishment" ]      },{         "formatted_address" : "Kempischesteenweg 27,"geometry" : {            "location" : {               "lat" : 50.9350770,"lng" : 5.3397760            }         },"id" : "dc66d311b3c4f5d1a87d5959dfdbc7616ad10b24","name" : "Oberonn","opening_hours" : {            "open_now" : true         },"reference" : "CnRlAAAA5q-rz_aOTWsFGQIJz_6zyLbXIczXOTq4PVFxniOjxsCwnw7uIfY8tu7Jk-QbJ-arMWgdClnSpX28q2SqxD8021LGWcaf4Sgo9MaXWpoD6c4TSagyVO9_l_HUXgMoOFJzhHG_NH6z-t1DPxT1zD19PhIQ2gBP9cLazKeB96ZDTpFdsxoUVGB2Ddhrq6JUoTJgrHGL-SINOWk",{         "formatted_address" : "Willekensmolenstraat 41,"geometry" : {            "location" : {               "lat" : 50.9316830,"lng" : 5.3470750            }         },"id" : "04937541c2bf71ebec7ac13d506dbbd2727e1ce3","name" : "Den DrosSAErd","reference" : "CnRqAAAA0cPmuMx0_J4x-o-yn0oT1D3kD-IHYAQPotAPPeDD3DWh2FXkD89kCsYoUGDLBlH2mKY6ju18JyCHvc4W_izLcd6TUOIoXrbUCyrtxOL4sTAFb41kH1aFT4dOBgvigYrGIcV8Qbzq-K4YGL3t7pnf1hIQKmUp-LLqtGHb4waYi2nq8hoU3VgwykpytoSUUPe2Ue1HmPrMRtE",{         "formatted_address" : "Leopoldplein 1,"geometry" : {            "location" : {               "lat" : 50.9275810,"lng" : 5.3363830            }         },"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png","id" : "cc30d6f4e6b0db1ed6dfd17bac118bbf78f194ae","name" : "Century (Hotel)","rating" : 3.80,"reference" : "CnRsAAAAfw4ucOBllDjMCtRU9epYQelpKHRx3u8JR8jr4I5jFzJsktNn3Un-3LjKKWtXCk3Unofi_6RhPFw9Tp8VU_Z7i-WOa00P-pirtCDjQPxg7sp470Mgh6_6PQspGG39H3k-VIMuUz9HWmoP3sPjump6SRIQTp1LZghfi-_HVaMfQArGPxoU-6ogK2IGMiueMEXP9mFiHlGJmo8","types" : [ "lodging",{         "formatted_address" : "Maastrichterstraat 30,"geometry" : {            "location" : {               "lat" : 50.9295410,"lng" : 5.3391230            }         },"id" : "352f9da4642588aba419353487b210baeb30ddd3","name" : "In De Kleine Hal","reference" : "CnRuAAAAAlnMpdiL4Kluiw1T0-QgKWFv9wwWvrSY4w-B7SLI7gvpqT0FYaMTl6DhxncPLqRyxOTWxw3DP3r1XvNHDKXnAb3eRM-gZYwIqbvzVq62zEZgGw0usQgf48mAWOrDpegdNLnEFRYkIduRwlDMDyIOyBIQlDs9BozH4m_gE-dZKZf7yxoUqw0H_HT_IQnLaVm0YwG1QV7o3kg",{         "formatted_address" : "Fruitmarkt 32,"geometry" : {            "location" : {               "lat" : 50.9299760,"lng" : 5.3393550            }         },"icon" : "http://maps.gstatic.com/mapfiles

11-03 14:47:13.864: D/URL INPUT(19532): https://maps.googleapis.com/maps/api/place/textsearch/json?query=cafe+in+Elfde-Liniestraat%2C+Hasselt%2C+Belgium&pagetoken=ClRHAAAAqYa7IpwMQH3q1DyinfsMnkuOaZg8wQrp0pvzarv13pwqruqT2YfaEry6v_d-L4d_TC13G6iHuPz-rc1KbI6XRE01rB5CuXcHISu-CI_CaKESEMUxSjHhHDNee4xbr2tPEZcaFPvO6xlRDjs-5AixyD9vamWwTGlU&sensor=true&key=

PS:当我在我的浏览器中使用代码时(使用next_page_token)两种方式都是正确的,只有我的Android应用程序才能获得有效数据.是的我有一个API密钥,但是我从代码和我的logcat输出删除了它.

谁知道我在这里做错了什么?

编辑
当我在Android中硬编码我的网址(带有next-page-token),然后让它运行.我得到了我期望的数据,因此没有返回Invalid_Request.问题在于构建Android中的URL或URL类的使用.

最佳答案
在我自己的问题上找到答案:过了一会儿,我只需要更好地检查我的logcat输出.

从谷歌发回数据的请求次数.

>请求的输出时间1:14:47:13:832
>请求输入时间2:14:47:13:864
>请求的输出时间2:14:47:13:989

这些时间彼此接近,在我看来谷歌认为我是垃圾邮件发送者/黑客或其他东西,并拒绝我在第二次请求时访问服务器.

如果有next_page_token,我的解决方案是等待1秒,然后发送后续请求.

原文链接:https://www.f2er.com/android/430711.html

猜你在找的Android相关文章