Код: Выделить всё
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