如何使用 Google Place Add in Python

How to use Google Place Add in Python

我在 Python 中为 Web 服务 使用 Google Place API。 我正在尝试添加像 the tutorial here

这样的地方

我的代码在这里:

from googleplaces import GooglePlaces, types, lang, GooglePlacesError, GooglePlacesAttributeError

API_KEY = "[Google Place API KEY]"
google_places = GooglePlaces(API_KEY)

try:
    added_place = google_places.add_place(
        name='Mom and Pop local store',
        lat_lng={'lat': 51.501984, 'lng': -0.141792},
        accuracy=100,
        types=types.TYPE_HOME_GOODS_STORE,
        language=lang.ENGLISH_GREAT_BRITAIN)

except GooglePlacesError as error_detail:
    print error_detail

但是我一直收到这个错误:

我试着把输入改成Json格式或者Python字典格式,结果报错"google_places.add_place() only accept 1 parameter, 2 give"……

有没有什么正确的方法可以使用GooglePlaceAPI在Python中添加Place方法

哦,终于找到解决办法了,就这么简单...我不熟悉Python POST请求,其实一切都很简单。

只需要这里的代码,我们就可以在Google地方添加一个地方API,用Python:

import requests

post_url = "https://maps.googleapis.com/maps/api/place/add/json?key=" + [YOUR_API_KEY]

r = requests.post(post_url, json={
  "location": {
    "lat": -33.8669710,
    "lng": 151.1958750
  },
  "accuracy": 50,
  "name": "Google Shoes!",
  "phone_number": "(02) 9374 4000",
  "address": "48 Pirrama Road, Pyrmont, NSW 2009, Australia",
  "types": ["shoe_store"],
  "website": "http://www.google.com.au/",
  "language": "en-AU"
})

查看结果:

print r.status_code
print r.json()