相片
透過 client.photos 新增、列出、移除地點相片,以及為相片加上星號。
所有照片方法都位於 client.photos 下。除了 upload_status 之外,每個方法都接受 location_id,而 location_id 接受數字或 base64 編碼的 ID,請參閱地點 ID。
照片透過公開 URL 附加,而非以 multipart 表單資料上傳:您負責託管圖片,平台會擷取圖片,後續處理則在背景繼續進行。照片類型為 LOGO、COVER 和 ADDITIONAL。
photos.list
取得附加至地點的媒體檔案,包括已加星號和未加星號的檔案。
client.photos.list(location_id: str | int) -> list[APIObject]photos = client.photos.list(16808)for photo in photos: print(photo.id, photo.categoryName, photo.starred)傳回 mediaFilesOfLocation 清單。每個項目都有 id、url、thumbnailUrl、categoryName、categoryId、fileType、starred 和 viewsCount。id 就是您要傳入 remove 和 star 的值。請參閱取得地點的照片。
photos.add
將一張或多張照片附加至地點。photos 中的每個項目都需要一個儲存公開圖片 URL 的 photo 鍵,以及一個 type 鍵。
client.photos.add( location_id: str | int, photos: list[dict[str, Any]],) -> APIObjectresult = client.photos.add(16808, [ {"photo": "https://cdn.example.com/acme-logo.png", "type": "LOGO"}, {"photo": "https://cdn.example.com/acme-storefront.jpg", "type": "ADDITIONAL"},])for photo in result.photos: print(photo.id, photo.type)傳回包含 success、photos、request 和 errors 的 addLocationPhotos 物件。photos 中的每個項目都包含 id、databaseId、url、thumbnailUrl、type 和 starred。請參閱將照片上傳至地點。
photos.remove
依媒體 ID 解除照片與地點的關聯。
client.photos.remove( location_id: str | int, photo_ids: list[str],) -> APIObjectresult = client.photos.remove(16808, ["TWVkaWFGaWxlOjU4Nzg5MzE="])print(result.removedCount)傳回包含 removedCount 和 errors 的 removeLocationPhotos 物件。請參閱從地點移除照片。
photos.star
為照片加上或移除星號,讓支援此功能的發布平台優先顯示加上星號的照片。傳入 starred=False 即可移除星號。每個帳號最多可為 4 張照片加上星號。
client.photos.star( location_id: str | int, media_ids: list[str], *, starred: bool = True,) -> APIObjectPython 參數名為 media_ids,其中儲存的媒體 id 值與 photos.list 傳回的值相同。SDK 在實際傳輸時會將這些值放在 photoIds 欄位中,因此您完全不需要自行建立該欄位。
# Star two photosclient.photos.star(16808, ["TWVkaWFGaWxlOjU4Nzg5MzI=", "TWVkaWFGaWxlOjU4Nzg5MzM="]) # Unstar oneresult = client.photos.star(16808, ["TWVkaWFGaWxlOjU4Nzg5MzI="], starred=False)for photo in result.photos: print(photo.id, photo.starred)傳回包含 success、photos 和 error 的 starUnstarLocationPhotos 物件。請參閱為地點照片加上星號。
photos.upload_status
檢查大量照片上傳的進度。當您一次新增多張照片,且需要每張圖片的結果時,請輪詢此方法。
client.photos.upload_status(request_id: str) -> APIObjectstatus = client.photos.upload_status("e6c2d9d9-9a18-4015-88cf-9a4e19a6f49a")print(status.to_dict())如需每張照片的狀態與錯誤欄位,包括可能隨照片結果傳回的拒絕原因,請參閱檢查大量照片上傳狀態。