帖子
通过 client.posts 向 Google 和 Facebook 发布公告、活动和优惠。
所有帖子方法都位于 client.posts 下。接收 location_id 的方法支持数字 ID 或经 base64 编码的 ID;请参阅地点 ID。
帖子可发布到 2 个站点:GOOGLE 和 FACEBOOK。帖子类型包括 ANNOUNCEMENT、EVENT、OFFER、COVID19 和 PRODUCT。行动号召类型包括 BOOK、ORDER、SHOP、LEARN_MORE、SIGN_UP 和 GET_OFFER;cta_type 和 cta_url 必须始终一起提供。
异步发布
发布以异步方式进行。创建调用返回 status: INPROGRESS;请轮询 posts.retrieve()(批量发布活动则轮询 posts.bulk_retrieve()),直到状态为 SUCCESS,并检查 publishDetails[].submissionError 以了解各站点的失败情况。
按站点设置消息
每个创建方法的 message 都可以是纯字符串,此时所有站点都会发布相同文本,也可以是将站点映射到文本的 dict:
message = { "GOOGLE": "Book your summer checkup today!", "FACEBOOK": "Summer checkups are here. Tag a friend who needs one!",}当 message 为 dict 时,其中必须包含 sites 中每个站点对应的条目;如果缺少任何条目,SDK 会在发起任何网络调用之前抛出 ValidationError。
posts.bulk_publish
通过一次调用,为多个地点在 Google 和 Facebook 上发布同一篇帖子。这是推荐的发帖方式:sites 默认包含这两个站点,单条消息(或按站点设置的 dict)会展开为每个站点一个条目,地点 ID 会自动编码,并且在发起任何网络调用之前,会在客户端验证请求载荷。
client.posts.bulk_publish( *, name: str, location_ids: list[str | int], message: str | dict[str, str], sites: list[str] | None = None, post_type: str = "ANNOUNCEMENT", cta_type: str | None = None, cta_url: str | None = None, media_url: str | None = None, scheduled_dates: dict | None = None, context_info: dict | None = None, additional_fields: dict | None = None,) -> APIObjectresult = client.posts.bulk_publish( name="Holiday hours", location_ids=[16808, 16809, 16810], message="Open until 10pm through the holidays!", media_url="https://cdn.example.com/holiday.jpg", cta_type="LEARN_MORE", cta_url="https://example.com/holiday-hours",)print(result.socialPost.id, result.socialPost.status) # INPROGRESS, publishes asyncposts.create_announcement
创建 ANNOUNCEMENT 帖子:包含纯文本消息,以及可选的 CTA 和媒体。sites 默认为 ["GOOGLE"]。
client.posts.create_announcement( *, name: str, location_ids: list[str | int], message: str | dict[str, str], sites: list[str] | None = None, cta_type: str | None = None, cta_url: str | None = None, media_url: str | None = None, scheduled_dates: dict | None = None, additional_fields: dict | None = None,) -> APIObjectresult = client.posts.create_announcement( name="Grand Opening", location_ids=[16808], message="Acme Dental is now open!", sites=["GOOGLE"], cta_type="LEARN_MORE", cta_url="https://acmedental.example.com/opening",)print(result.socialPost.id)posts.create_event
创建包含标题和起止时间范围的 EVENT 帖子。Google 要求提供活动标题;如果缺少标题,SDK 会抛出 ValidationError。start_day 和 end_day 是日期(YYYY-MM-DD);start_time 和 end_time 是用于显示的字符串,例如 "10:00am"。
client.posts.create_event( *, name: str, location_ids: list[str | int], message: str | dict[str, str], title: str, start_day: str, end_day: str, start_time: str | None = None, end_time: str | None = None, sites: list[str] | None = None, cta_type: str | None = None, cta_url: str | None = None, media_url: str | None = None, scheduled_dates: dict | None = None, additional_fields: dict | None = None,) -> APIObjectresult = client.posts.create_event( name="Free checkup day", location_ids=[16808], message="Join us for free dental checkups!", title="Free Checkup Day", start_day="2026-08-01", end_day="2026-08-01", start_time="10:00am", end_time="4:00pm", cta_type="BOOK", cta_url="https://acmedental.example.com/book",)print(result.socialPost.id)posts.create_offer
创建包含优惠券、折扣和条款的 OFFER 帖子。title 用于命名优惠,为必填项;start_day 和 end_day(YYYY-MM-DD)限定优惠的有效期。
client.posts.create_offer( *, name: str, location_ids: list[str | int], message: str | dict[str, str], title: str, coupon_code: str | None = None, discount: str | None = None, redeem_url: str | None = None, terms_conditions: str | None = None, start_day: str | None = None, end_day: str | None = None, sites: list[str] | None = None, cta_type: str | None = None, cta_url: str | None = None, media_url: str | None = None, scheduled_dates: dict | None = None, additional_fields: dict | None = None,) -> APIObjectresult = client.posts.create_offer( name="Summer whitening sale", location_ids=[16808], message="20% off teeth whitening all week!", title="Summer Whitening Sale", coupon_code="SUMMER20", discount="20%", redeem_url="https://acmedental.example.com/sale", terms_conditions="One per patient. Not valid with other offers.", start_day="2026-08-01", end_day="2026-08-07",)print(result.socialPost.id)posts.create
使用原始请求体 dict 创建帖子。您在 camelCase 中以扁平结构传入字段,辅助函数会在发送前将这些字段封装到 API 要求的 input 对象中:实际传输的请求体为 {"input": {...}},绝不会是扁平结构的请求体。locationIds 必须已进行 base64 编码。建议优先使用上述带类型的创建方法,以使用关键字参数、自动 ID 编码和客户端验证。
client.posts.create(body: dict) -> APIObject必填项:postName、locationIds(base64)、postType、postSites。
result = client.posts.create({ "postName": "Grand Opening", "locationIds": ["TG9jYXRpb246MTY4MDg="], "postType": "ANNOUNCEMENT", "postSites": ["GOOGLE"], "postMessage": [{"site": "GOOGLE", "message": "We are now open!"}],})print(result.socialPost.id)posts.retrieve
获取帖子及其内容、各站点的发布状态和分析数据。创建后轮询此方法,直到 status 为 SUCCESS。
client.posts.retrieve(post_id: str) -> APIObjectpost = client.posts.retrieve("U29jaWFsUG9zdDo0NDEyMg==")print(post.status)for detail in post.publishDetails: print(detail.site, detail.submissionError)posts.delete
删除帖子,并将其从所有已发布到的站点移除。
client.posts.delete(post_id: str) -> APIObjectclient.posts.delete("U29jaWFsUG9zdDo0NDEyMg==")posts.list_for_location
列出以某个地点为目标的帖子发布活动。采用偏移量分页:结果包含 .records,以及含有 totalPages、totalRecords 和 hasNextPage 的 .pageInfo。返回数据位于 postsByLocation 下。
此路由拒绝接收 tag,因此从 0.5.3 起,SDK 为了向后兼容而接受该参数,但绝不会在实际请求中发送它。需要按标签筛选时,请使用 posts.bulk_list_for_location。
client.posts.list_for_location( location_id: str | int, *, tag: str = "all", page: int | None = None, per_page: int | None = None, filters: dict | None = None, sort_fields: dict | None = None,) -> APIObjectresult = client.posts.list_for_location(16808, page=1, per_page=10)for post in result.records: print(post.id, post.name)print(result.pageInfo.totalRecords)posts.bulk_retrieve
获取批量(多地点)发布活动,包括各地点的发布状态和分析数据。
client.posts.bulk_retrieve(bulk_post_id: str) -> APIObjectbulk = client.posts.bulk_retrieve("QnVsa1Bvc3Q6OTk=")print(bulk.status)posts.bulk_list_for_location
列出包含某个地点的批量(多地点)发布活动。参数和结果结构与 posts.list_for_location 相同。
client.posts.bulk_list_for_location( location_id: str | int, *, tag: str = "all", page: int | None = None, per_page: int | None = None, filters: dict | None = None, sort_fields: dict | None = None,) -> APIObjectresult = client.posts.bulk_list_for_location(16808, page=1, per_page=10)for campaign in result.records: print(campaign.id, campaign.name)