POST/api/v4/social/brands/{brandId}/connections/link

获取连接链接

返回一个短期有效的托管 URL,引导最终用户将一个社交平台连接到一个品牌。

需要 API 密钥。请求头格式和密钥轮换请参阅身份验证。

参数

路径

名称类型必填描述
brandIdstring必填Brand UUID the connection will be attached to.

请求体

名称类型必填描述
channelstring必填Platform to connect: `FACEBOOK`, `INSTAGRAM`, `TWITTER` (X), `LINKEDIN` or `PINTEREST`.
redirectUrlstring必填Absolute https URL in your application the user is returned to when the flow finishes. Must be a URL you control.
errorUrlstring可选Absolute https URL the user is returned to if they cancel or the platform rejects the authorization. Defaults to `redirectUrl` when omitted.
statestring可选Opaque string echoed back on the return URL unchanged. Use it to correlate the return with the session that started the flow; it is not validated or interpreted.

请求示例

可直接粘贴的请求体。请将占位 ID 和值替换为您自己的。

Request body
{  "channel": "INSTAGRAM",  "redirectUrl": "https://app.example.com/social/connected",  "errorUrl": "https://app.example.com/social/connect-failed",  "state": "sess_9f2c1e64"}

响应

200Link generated. Redirect the end user to `url`; `expiresIn` is how many seconds it stays valid.
Response
{  "data": {    "connectSocialAccount": {      "status": "success",      "url": "https://social.listingsapi.com/connect/start?token=bfac8e06-8d72-4810-9c50-ae7ee12a7b52",      "title": null,      "token": null,      "expiresIn": 900    }  }}
200The link could not be issued. `status` is `failed` and `title` carries the reason: most often the account is at its connection cap (`SY95042`, counted on billable connections, so recent disconnects have not freed room) or the platform is not enabled for the account (`SY95044`).
Response
{  "data": {    "connectSocialAccount": {      "status": "failed",      "url": null,      "title": "SY95042: Connection limit reached for this account",      "token": null,      "expiresIn": null    }  }}
401Unauthenticated, missing or invalid API key.
404No brand with that ID on this account (`SY95043`).

签发一个短期有效的 URL,用于将一个社交平台连接到一个品牌。您无需处理该平台的 OAuth 凭据:将最终用户重定向到返回的 url,用户在平台的授权页面上完成授权,并选择要发布内容的主页、看板或组织,随后返回您的 redirectUrl。

这是 Social 中唯一使用扁平请求体的写入操作。Social API 中的其他所有写入操作都封装在 input 对象中;此操作则不封装。请在顶层发送 channel、redirectUrl,以及可选的 errorUrl 和 state。

使用场景:在您的产品中自助连接渠道。向用户展示 5 个平台,用户选择其中一个后,使用该 channel 和标识其会话的 state 调用此端点。将用户重定向到 url。当用户返回您的 redirectUrl 且携带 status=success 时,轮询 GET /social/brands/{brandId}/connections,直到新渠道出现,然后让用户通过 POST /social/posts 撰写第一篇帖子。

用户返回的目标地址

流程结束后,用户会被重定向到您的 redirectUrl(或 errorUrl),并附加以下查询参数:

参数是否始终存在说明
status是success 或 error。
brandId是该连接所关联的品牌。与您调用时使用的路径参数一致。
platform是已连接的平台,例如 INSTAGRAM。
state仅在您发送了该参数时您提供的不透明值,原样返回。
connectedAccountId仅在 status=success 时新连接的 UUID,与连接列表中显示的 id 相同。
Code
https://app.example.com/social/connected  ?status=success  &brandId=6f2c9a41-7b0e-4d55-9a2f-3c8e1d47b902  &platform=INSTAGRAM  &state=sess_9f2c1e64  &connectedAccountId=b81d5b3c-4a90-4f6a-9c11-71e0dd2fa4a7

注意事项。

  • 链接会过期。expiresIn 包含其有效期,单位为秒。该链接只能使用一次:请在用户点击“连接”时签发,不要提前签发,也切勿存储。如果用户中途放弃流程,请再次调用此端点以获取新的 URL。
  • 连接记录会异步创建。用户返回您的 redirectUrl 时,连接记录尚需片刻才会创建,因此在用户返回后立即读取连接列表时,结果中没有该连接属于正常情况。请在几秒内轮询连接列表,不要将首次读取结果为空视为失败。
  • Instagram 需要已关联 Facebook 主页的商业账号或创作者账号。个人 Instagram 账号无法连接,平台的授权页面也不会提供此类账号供选择。如果您的用户遇到此问题,请让其在 Instagram 应用中转换账号类型,并将其关联到自己管理的主页,然后重新签发链接。
  • TWITTER 就是 X。为保持向后兼容,枚举值仍为 TWITTER;产品名称为 X。平台值是大写的枚举名称,发送 "instagram" 会被拒绝。
  • redirectUrl 和 errorUrl 必须是绝对 https URL。相对 URL 或 http URL 会被拒绝,并返回 SY95049。
  • 连接是按用量计费的资源。每个链接都会占用账户内共享连接池中的一个名额:Social Launch 提供 20 个连接,Social Growth 提供 125 个连接,每个每月 25 美元的连接包可额外增加 5 个连接,自助扩容上限为 250 个。品牌数量本身不受限制,因此容量不足时失败的始终是此调用,而不是创建品牌。连接池已满时,此调用会返回 status: "failed",并附带 SY95042。请参阅套餐和附加项,并从 GET /social/limits 查看剩余容量。
  • 这是地点级别的 Facebook 连接链接在 Social 中的对应功能,但二者属于不同的产品,在其中一个产品中建立的连接不会在另一个产品中显示。

写入操作:未在实际账户中执行。所示请求和响应根据 API schema 构建。

Request
curl -X POST 'https://listingsapi.com/api/v4/social/brands/<brandId>/connections/link' \  -H "Authorization: API $LISTINGSAPI_KEY" \  -H 'Content-Type: application/json' \  -d '{    "channel": "INSTAGRAM",    "redirectUrl": "https://app.example.com/social/connected",    "errorUrl": "https://app.example.com/social/connect-failed",    "state": "sess_9f2c1e64"  }'