Как правильно очистить все соединения для фотографии Google Street View с помощью API публикации Google Street View и PyPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как правильно очистить все соединения для фотографии Google Street View с помощью API публикации Google Street View и Py

Сообщение Anonymous »

Я пытаюсь очистить все соединения для фотографии Google Street View, используя клиентскую библиотеку Python google.streetview.publish_v1. Однако я сталкиваюсь с проблемами, из-за которых соединения не очищаются должным образом. Вот мой текущий код:

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

from google.streetview.publish_v1 import StreetViewPublishServiceClient
from google.streetview.publish_v1 import types, enums
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
import os
import pickle

def authenticate():
client_secrets_file = 'path_to_my_client_secrets_file.json'
scopes = ['https://www.googleapis.com/auth/streetviewpublish']
credentials = None

if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
credentials = pickle.load(token)

if not credentials or not credentials.valid:
if credentials and credentials.expired and credentials.refresh_token:
credentials.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)
credentials = flow.run_local_server(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(credentials, token)

return credentials

def initialize_streetview_publish_api():
credentials = authenticate()
client = StreetViewPublishServiceClient(credentials=credentials)
return client

def clear_connections(client, photo_id):
try:
# Specify the view parameter
photo = client.get_photo(photo_id=photo_id, view=enums.PhotoView.INCLUDE_DOWNLOAD_URL)
print(f"Original connections for {photo_id}: {photo.connections}")

# Clear connections
photo.connections.clear()
response = client.update_photo(photo=photo, update_mask=types.FieldMask(paths=['connections']))
print(f"Cleared connections for {photo_id}: {response.connections}")

# Verify that the connections have been cleared
updated_photo = client.get_photo(photo_id=photo_id, view=enums.PhotoView.INCLUDE_DOWNLOAD_URL)
print(f"Connections after clearing for {photo_id}: {updated_photo.connections}")

if not updated_photo.connections:
print(f"Successfully cleared all connections for {photo_id}.")
else:
print(f"Failed to clear all connections for {photo_id}.")
except Exception as e:
print(f"Error clearing connections for {photo_id}: {e}")

def main():
streetview_client = initialize_streetview_publish_api()

photo_id_to_update = 'my_photo_id'  # Change this to a placeholder

clear_connections(streetview_client, photo_id_to_update)
print(f"Deleted all connections for photo {photo_id_to_update}")

if __name__ == "__main__":
main()
Сценарий выполняется без ошибок, но соединения фактически не очищаются. Вот результат, который я получаю:

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

Original connections for my_photo_id: [target {
id: "some_target_id"
}
, target {
id: "another_target_id"
}
]
Cleared connections for my_photo_id: []
Connections after clearing for my_photo_id: [target {
id: "some_target_id"
}
, target {
id: "another_target_id"
}
]
Failed to clear all connections for my_photo_id.
Deleted all connections for photo my_photo_id

Process finished with exit code 0
Как правильно удалить все соединения для фотографии Просмотра улиц? Что-то не так с моим подходом или в моем коде отсутствует шаг?

Подробнее здесь: https://stackoverflow.com/questions/788 ... sing-googl
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

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