Получение обзоров сайтов Google с помощью PythonPython

Программы на Python
Anonymous
Получение обзоров сайтов Google с помощью Python

Сообщение Anonymous »

Мне нужно иметь возможность получать обзоры сайтов Google с помощью API, который помещает их в наше хранилище данных.
Я попробовал использовать следующий код:

Код: Выделить всё

from googleapiclient.discovery import build

API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxx'
service = build('**mybusiness**', 'v4', developerKey=API_KEY)

location_id = 'locations/xxxxxxxxxxxx'

# Request reviews
reviews = service.accounts().locations().reviews().list(parent=location_id).execute()
# Print review data
for review in reviews['reviews']:
print(f"Review: {review['review']}")
print(f"Rating: {review['starRating']}")
print('---')
Но я получаю сообщение об ошибке: mybusiness v4 не существует:

Код: Выделить всё

Traceback (most recent call last):
File "
\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\Lib\runpy.py", line 88, in _run_code
exec(code, run_globals)
File "\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in 
cli.main()
File "\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\src\DownloadGoogleReviewToDWH - test 2.py", line 4, in 
service = build('**mybusiness**', 'v4', developerKey=API_KEY)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Python312\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "Python312\site-packages\googleapiclient\discovery.py", line 304, in build
content = _retrieve_discovery_doc(
^^^^^^^^^^^^^^^^^^^^^^^^
File "Python312\site-packages\googleapiclient\discovery.py", line 417, in _retrieve_discovery_doc
content = discovery_cache.get_static_doc(serviceName, version)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Python312\site-packages\googleapiclient\discovery_cache\__init__.py", line 72, in get_static_doc
with open(os.path.join(DISCOVERY_DOC_DIR, doc_name), "r") as f:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: '\\local-packages\\Python312\\site-packages\\googleapiclient\\discovery_cache\\documents\\**mybusiness**.v4.json'
Я нашел информацию о том, что модуль mybusisness устарел, но все еще поддерживается, так ведь он должен работать? Хорошо, я нашел информацию, которую мне следует использовать.

Код: Выделить всё

service = build('**mybusinessbusinessinformation**', 'v1', developerKey=API_KEY)

# Request reviews
reviews = service.accounts().locations().reviews().list(parent=location_id).execute()

# Print review data
for review in reviews.get('reviews', []):
print(f"Review: {review['review']}")
print(f"Rating: {review['starRating']}")
print('---')
Теперь я получаю сообщение об ошибке: «Объект «Ресурс» не имеет атрибута «отзывы»»:

Код: Выделить всё

Traceback (most recent call last):
File "
\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\Lib\runpy.py", line 88, in _run_code
exec(code, run_globals)
File "\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in 
cli.main()
File "\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\src\DownloadGoogleReviewToDWH - test 2.py", line 9, in 
reviews = service.accounts().locations().reviews().list(parent=location_id).execute()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Resource' object has no attribute 'reviews'
Я начал читать документацию, но не нашел ничего о том, где найти отзывы.
https://developers.google.com/my-busine ... formation/ rest/v1/accounts.locations
Кто-нибудь сталкивался с такой же проблемой и нашел ее решение?

Подробнее здесь: https://stackoverflow.com/questions/790 ... ith-python

Вернуться в «Python»