照片

通过 client.photos 添加、列出、删除地点照片,以及为地点照片加星标。

所有照片方法都位于 client.photos 下。除 upload_status 外,每个方法都接受 location_id,而 location_id 接受数字或 base64 编码的 ID,参见地点 ID。

照片通过公开 URL 关联,而不是作为 multipart 表单数据上传:您负责托管图片,平台负责获取图片,后续处理在后台继续进行。照片类型为 LOGO、COVER 和 ADDITIONAL。


photos.list

获取与地点关联的媒体文件,包括已加星标和未加星标的文件。

Python
client.photos.list(location_id: str | int) -> list[APIObject]
Python
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 键。

Python
client.photos.add(    location_id: str | int,    photos: list[dict[str, Any]],) -> APIObject
键类型说明
photostr要获取的图片的公开 URL。
typestrLOGO、COVER 或 ADDITIONAL。
Python
result = 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 解除照片与地点的关联。

Python
client.photos.remove(    location_id: str | int,    photo_ids: list[str],) -> APIObject
Python
result = client.photos.remove(16808, ["TWVkaWFGaWxlOjU4Nzg5MzE="])print(result.removedCount)

返回包含 removedCount 和 errors 的 removeLocationPhotos 对象。参见从地点移除照片。


photos.star

为照片添加或取消星标,以便支持此功能的发布平台优先展示带星标的照片。传入 starred=False 可取消星标。每个账户最多可为 4 张照片添加星标。

Python
client.photos.star(    location_id: str | int,    media_ids: list[str],    *,    starred: bool = True,) -> APIObject

Python 参数名为 media_ids,其中存放的媒体 id 值与 photos.list 返回的值相同。SDK 在网络请求中将这些值作为 photoIds 字段发送,因此您无需自行构造该字段。

Python
# 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

检查批量照片上传的进度。如果您一次添加了多张照片,并且需要获取每张图片的处理结果,请轮询此方法。

Python
client.photos.upload_status(request_id: str) -> APIObject
Python
status = client.photos.upload_status("e6c2d9d9-9a18-4015-88cf-9a4e19a6f49a")print(status.to_dict())

有关每张照片的状态和错误字段,包括可能返回的照片拒绝原因,请参见检查批量照片上传状态。


另请参阅

  • 上传地点照片:涵盖完整流程的照片指南,包括大小限制
  • 地点:创建和更新照片所关联的地点
  • 帖子:使用 media_url 为帖子附加一张图片