我在哪里可以找到适用于Python的Google Places API客户端库? [英] Where do I find the Google Places API Client Library for Python?

查看:89
本文介绍了我在哪里可以找到适用于Python的Google Places API客户端库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它不在此处支持的库下:
https: //developers.google.com/api-client-library/python/reference/supported_apis

It's not under the supported libraries here: https://developers.google.com/api-client-library/python/reference/supported_apis

它仅适用于Python吗?如果没有,那么可以使用哪种语言?

Is it just not available with Python? If not, what language is it available for?

推荐答案

Andre的回答指出您在引用API的正确位置。由于你的问题是python特定的,请允许我向你展示一个基本的方法来在python中构建你提交的搜索URL。在您注册Google的免费API密钥后的几分钟内,该示例将帮助您一路搜索内容。

Andre's answer points you at a correct place to reference the API. Since your question was python specific, allow me to show you a basic approach to building your submitted search URL in python. This example will get you all the way to search content in just a few minutes after you sign up for Google's free API key.

ACCESS_TOKEN = <Get one of these following the directions on the places page>

import urllib

def build_URL(search_text='',types_text=''):
    base_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'     # Can change json to xml to change output type
    key_string = '?key='+ACCESS_TOKEN                                           # First think after the base_url starts with ? instead of &
    query_string = '&query='+urllib.quote(search_text)
    sensor_string = '&sensor=false'                                             # Presumably you are not getting location from device GPS
    type_string = ''
    if types_text!='':
        type_string = '&types='+urllib.quote(types_text)                        # More on types: https://developers.google.com/places/documentation/supported_types
    url = base_url+key_string+query_string+sensor_string+type_string
    return url

print(build_URL(search_text='Your search string here'))

这段代码将构建并打印一个URL,用于搜索最后一行代替Your search string here的内容。您需要为每个搜索建立其中一个网址。在这种情况下,我已经打印了它,以便您可以将其复制并粘贴到浏览器地址栏中,这会让您返回(在浏览器中)JSON文本对象,就像程序提交该URL时所获得的一样。我建议使用python 请求库在程序中获取该信息,您可以简单地通过获取返回的URL来执行此操作:

This code will build and print a URL searching for whatever you put in the last line replacing "Your search string here". You need to build one of those URLs for each search. In this case I've printed it so you can copy and paste it into your browser address bar, which will give you a return (in the browser) of a JSON text object the same as you will get when your program submits that URL. I recommend using the python requests library to get that within your program and you can do that simply by taking the returned URL and doing this:

response = requests.get(url)

接下来你需要解析返回的JSON响应,您可以通过将它转换为 json 库来进行解析(查找)。在通过json.loads运行该响应之后,您将拥有一个包含所有结果的好Python字典。您也可以将该返回(例如,从浏览器或保存的文件)粘贴到在线JSON查看器以在编写代码时了解结构以访问json.loads出来的字典。

Next up you need to parse the returned response JSON, which you can do by converting it with the json library (look for json.loads for example). After running that response through json.loads you will have a nice python dictionary with all your results. You can also paste that return (e.g. from the browser or a saved file) into an online JSON viewer to understand the structure while you write code to access the dictionary that comes out of json.loads.

如果部分内容不清楚,请随时发布更多问题。

Please feel free to post more questions if part of this isn't clear.

这篇关于我在哪里可以找到适用于Python的Google Places API客户端库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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