识别卡片

简介

卡片是使用媒体的可定制广告形式,可与网站、应用或行动号召关联,以促进特定用户的互动性,例如发送私信。卡片可附加到推文、预排期推文或草稿推文中。

可选择以下两种方式中的一种在推文对象中引用卡片:通过卡片的 card_uri 或通过其 preview_url。每个参数的示例值如下。

card_uri preview_url
card://1043282691834048513 https://cards.twitter.com/cards/18ce54d4x5t/68w3s

注意:自广告 API 版本 3 起,新创建的卡片在卡片响应中将仅生成并返回 card_uri

注意:自广告 API 版本 5 起,卡片响应中不再返回 preview_url

推文对象响应中引用的类型将取决于推文的创建方式。换言之,如果推文使用 card_uri 请求参数创建,则响应中会显示卡片 URI 值。相反,如果推文文本中包含了 preview_url,则响应中会显示预览 URL。

通过 card_uri 识别推文

对于使用卡片 URI 值创建的推文,在 card_uri 响应属性中可以找到对该卡片的引用。下面的响应示例使用 GET accounts/:account_id/tweets 端点。

$ twurl -H ads-api.twitter.com "/9/accounts/18ce54d4x5t/tweets?trim_user=true&tweet_type=PUBLISHED&tweet_ids=1043551275923591168"
{
  "request": {
    "params": {
      "tweet_ids": [
        "1043551275923591168"
      ],
      "tweet_type": "PUBLISHED",
      "trim_user": true,
      "account_id": "18ce54d4x5t"
    }
  },
  "next_cursor": null,
  "data": [
    {
      "coordinates": null,
      "retweeted": false,
      "source": "Ads API Internal Test App",
      "entities": {
        "hashtags": [],
        "symbols": [],
        "user_mentions": [],
        "urls": []
      },
      "display_text_range": [
        0,
        15
      ],
      "favorite_count": 0,
      "in_reply_to_status_id_str": null,
      "geo": null,
      "id_str": "1043551275923591168",
      "scopes": {
        "followers": false
      },
      "in_reply_to_user_id": null,
      "truncated": false,
      "retweet_count": 0,
      "scheduled_status": null,
      "id": 1043551275923591168,
      "in_reply_to_status_id": null,
      "nullcast": true,
      "created_at": "Sat Sep 22 17:23:07 +0000 2018",
      "place": null,
      "scheduled_at": null,
      "tweet_type": "PUBLISHED",
      "favorited": false,
      "card_uri": "card://1043282691834048513",
      "full_text": "Tracking a card",
      "lang": "en",
      "contributors": [
        2417045708
      ],
      "in_reply_to_screen_name": null,
      "in_reply_to_user_id_str": null,
      "user": {
        "id": 756201191646691328,
        "id_str": "756201191646691328"
      },
      "tweet_id": "1043551275923591168"
    }
  ]
}

如果使用标准 API,请在请求中使用 include_card_uri=true

无论使用哪个端点,只有推文是使用卡片 URI 创建的时,才会显示 card_uri 响应属性。

对于预排期推文和草稿推文对象,响应将始终包含 card_uri 响应属性。

通过 preview_url 识别推文

对于通过将预览 URL 纳入推文文本内容而创建的推文,可在 entities["urls"][i]["expanded_url"] 中查看 URL(text 字段中包含了缩略 t.co URL),其中 i 是数组索引(一条推文可包含多个 URL)。

对于预排期推文和草稿推文对象,预览 URL 会始终显示在 text 字段中。

提取卡片

如需检索关于特定卡片的其他信息,我们提供了两个端点:GET accounts/:account_id/cards/allGET accounts/:account_id/cards/all/:card_id。第一个端点通过 card_uri 提取卡片,第二个端点通过卡片 ID 进行提取。卡片 ID 可在 preview_url 末尾查看。在上述示例中,卡片 ID 为 68w3s。