使用LinkedIn新版Marketing API发布企业主页帖子遇DSC默认启用问题
解决LinkedIn Marketing API发布企业主页帖子的DSC强制校验问题
问题场景
使用LinkedIn新版Marketing API发布企业主页帖子,遵循官方示例编写请求后,收到如下400错误:
{"errorDetailType":"com.linkedin.common.error.BadRequest","code":"MISSING_REQUIRED_FIELD_FOR_DSC","message":"Field /adContext/dscAdAccount is required when the post is a Direct Sponsored Content, but missing in the request","errorDetails":{"inputErrors":[{"description":"Field /adContext/dscAdAccount is required when the post is a Direct Sponsored Content, but missing in the request","input":{"inputPath":{"fieldPath":"/adContext/dscAdAccount"}},"code":"MISSING_REQUIRED_FIELD_FOR_DSC"}]},"status":400}
用户明确不想使用Direct Sponsored Content(DSC),但isDsc为只读字段无法手动禁用。
问题根源
请求中distribution.feedDistribution被设置为"NONE",这一配置会被LinkedIn判定为DSC帖子,触发必须提供DSC广告账户的校验逻辑。
修复方案
将distribution.feedDistribution修改为"MAIN_FEED"(普通企业主页帖子的默认分发渠道),即可避免被识别为DSC帖子,无需额外提供DSC相关字段。
修改后的代码示例
content = "x" headers = { "Authorization": f"Bearer {self.access_token}", "X-Restli-Protocol-Version": "2.0.0", "LinkedIn-Version": "202207", "Content-Type": "application/json", } author = f"urn:li:organization:{self.page_id}" data = { "author": author, "commentary": content, "visibility": "PUBLIC", "distribution": { "feedDistribution": "MAIN_FEED", # 关键修改:替换为MAIN_FEED "targetEntities": [], "thirdPartyDistributionChannels": [] }, "lifecycleState": "PUBLISHED", "isReshareDisabledByAuthor": False, } response = requests.post("https://api.linkedin.com/rest/posts", headers=headers, json=data) return response
简化版(无需特殊分发配置时)
如果不需要自定义分发规则,可直接省略distribution字段,LinkedIn会自动使用默认的MAIN_FEED配置:
content = "x" headers = { "Authorization": f"Bearer {self.access_token}", "X-Restli-Protocol-Version": "2.0.0", "LinkedIn-Version": "202207", "Content-Type": "application/json", } author = f"urn:li:organization:{self.page_id}" data = { "author": author, "commentary": content, "visibility": "PUBLIC", "lifecycleState": "PUBLISHED", "isReshareDisabledByAuthor": False, } response = requests.post("https://api.linkedin.com/rest/posts", headers=headers, json=data) return response
说明
设置feedDistribution为"MAIN_FEED"后,帖子会正常发布到企业主页的主信息流中,完全符合普通非DSC帖子的发布需求,不会触发DSC相关的校验逻辑。
内容的提问来源于stack exchange,提问作者jackaaxc
相关产品推荐
相关产品推荐

