2016-09-19 27 views
0

我在Python中使用Google Place API for Web Service。 和我想要添加的地方,如the tutorial here如何使用Google Place在Python中添加

我的代碼如下:

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 

但我一直收到此錯誤: error

我試圖改變輸入JSON格式或Python字典格式,然後它給了錯誤「google_places.add_place()只接受1參數,2給」......

是否有任何正確的方式來使用Google Place API 在Python中添加地方法

回答

0

哦,終於找到了解決方案,它非常簡單......我不熟悉Python POST請求,事實上一切都很簡單。

只需要代碼在這裏,我們將能夠添加一個地方在谷歌廣場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()