Creating a Video Direct Card with the Twitter Ads API, Twurl, and PyCharm
Required Parameters:
- account_id
- first_cta
- first_cta_welcome_message_id
- second_cta
- second_cta_welcome_message_id
- third_cta
- third_cta_welcome_message_id
- fourth_cta
- fourth_cta_welcome_message_id
- name
- recipient_user_id
- video_id
Request
twurl -X POST -H ads-api.twitter.com "/3/accounts/18ce54jkujt/cards/video_direct_message?name=four cta video dm card&first_cta=CTA 1&first_cta_welcome_message_id=975846176053489668&second_cta=CTA 2&second_cta_welcome_message_id=975846179819917318&third_cta=CTA 3&third_cta_welcome_message_id=975846178599337989&fourth_cta=CTA 4&fourth_cta_welcome_message_id=975846177261400070&recipient_user_id=878264826199502848&video_id=13_975896990835007488"
Response
{
"data": {
"second_cta_welcome_message_id": "975846179819917318",
"name": "four cta video dm card",
"first_cta": "CTA 1",
"first_cta_welcome_message_id": "975846176053489668",
"video_url": "https://video.twimg.com/amplify_video/vmap/975896990835007488.vmap",
"fourth_cta_welcome_message_id": "975846177261400070",
"recipient_user_id": "878264826199502848",
"video_owner_id": "878264826199502848",
"video_content_id": "975896990835007488",
"preview_url": null,
"fourth_cta": "CTA 4",
"id": "5hhpk",
"second_cta": "CTA 2",
"account_id": "18ce54jkujt",
"third_cta_welcome_message_id": "975846178599337989",
"video_hls_url": "https://video.twimg.com/amplify_video/975896990835007488/pl/__xVEjGkg5_bQtKp.m3u8",
"created_at": "2018-03-20T01:41:28Z",
"third_cta": "CTA 3",
"card_uri": "card://975910159502454784",
"updated_at": "2018-03-20T01:41:28Z",
"video_poster_url": "https://pbs.twimg.com/amplify_video_thumb/975896990835007488/img/X_NdthGM-TJCNTKc.jpg",
"deleted": false,
"card_type": "VIDEO_DIRECT_MESSAGE"
},
"request": {
"params": {
"second_cta_welcome_message_id": "975846179819917318",
"video_poster_height": "9",
"name": "four cta video dm card",
"first_cta": "CTA 1",
"first_cta_welcome_message_id": "975846176053489668",
"video_url": "https://video.twimg.com/amplify_video/vmap/975896990835007488.vmap",
"fourth_cta_welcome_message_id": "975846177261400070",
"recipient_user_id": "878264826199502848",
"video_owner_id": "878264826199502848",
"video_content_id": "975896990835007488",
"fourth_cta": "CTA 4",
"second_cta": "CTA 2",
"account_id": "18ce54jkujt",
"third_cta_welcome_message_id": "975846178599337989",
"video_hls_url": "https://video.twimg.com/amplify_video/975896990835007488/pl/__xVEjGkg5_bQtKp.m3u8",
"third_cta": "CTA 3",
"video_poster_url": "https://pbs.twimg.com/amplify_video_thumb/975896990835007488/img/X_NdthGM-TJCNTKc.jpg",
"video_poster_width": "16",
"card_type": "VIDEO_DIRECT_MESSAGE"
}
}
}
Add the DM Card to a Tweet
Request
twurl -X POST -H ads-api.twitter.com "/3/accounts/18ce54jkujt/tweet?text=Video Direct Message Card w/ Four CTAs&card_uri=card://975910159502454784&as_user_id=878264826199502848&trim_user=true"
Response
{
"data": {
"created_at": "Tue Mar 20 01:42:05 +0000 2018",
"id": 975910315572580400,
"id_str": "975910315572580352",
"text": "Video Direct Message Card w/ Four CTAs",
"truncated": false,
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": []
},
"source": "<a href=\"https://twitter.com/SamSchmir\" rel=\"nofollow\">Ads API Client</a>",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 878264826199502800,
"id_str": "878264826199502848"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"retweet_count": 0,
"favorite_count": 0,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"scopes": {
"followers": false
},
"card": {
"name": "2586390716:video_direct_message",
"url": "card://975910159502454784",
"card_type_url": "http://card-type-url-is-deprecated.invalid",
"binding_values": {
"player_url": {
"type": "STRING",
"string_value": "https://video.twimg.com/amplify_video/vmap/975896990835007488.vmap"
},
"cta2": {
"type": "STRING",
"string_value": "CTA 2"
},
"cta1": {
"type": "STRING",
"string_value": "CTA 1"
},
"cta4_wm_id": {
"type": "STRING",
"string_value": "975846177261400070"
},
"content_duration_seconds": {
"type": "STRING",
"string_value": "14"
},
"player_width": {
"type": "STRING",
"string_value": "16"
},
"player_stream_content_type": {
"type": "STRING",
"string_value": "video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\""
},
"player_content_id": {
"type": "STRING",
"string_value": "975896990835007488"
},
"cta3_wm_id": {
"type": "STRING",
"string_value": "975846178599337989"
},
"player_height": {
"type": "STRING",
"string_value": "9"
},
"cta3": {
"type": "STRING",
"string_value": "CTA 3"
},
"card_id": {
"type": "STRING",
"string_value": "0"
},
"cta2_wm_id": {
"type": "STRING",
"string_value": "975846179819917318"
},
"cta1_wm_id": {
"type": "STRING",
"string_value": "975846176053489668"
},
"player_owner_id": {
"type": "STRING",
"string_value": "878264826199502848"
},
"player_hls_url": {
"type": "STRING",
"string_value": "https://video.twimg.com/amplify_video/975896990835007488/pl/__xVEjGkg5_bQtKp.m3u8"
},
"player_stream_url": {
"type": "STRING",
"string_value": "https://video.twimg.com/amplify_video/vmap/975896990835007488.vmap"
},
"cta4": {
"type": "STRING",
"string_value": "CTA 4"
},
"recipient": {
"type": "USER",
"user_value": {
"id_str": "878264826199502848",
"path": []
}
},
"player_image_small": {
"type": "IMAGE",
"image_value": {
"url": "https://pbs.twimg.com/amplify_video_thumb/975896990835007488/img/X_NdthGM-TJCNTKc.jpg",
"width": 1280,
"height": 720,
"alt": null
}
},
"player_image": {
"type": "IMAGE",
"image_value": {
"url": "https://pbs.twimg.com/amplify_video_thumb/975896990835007488/img/X_NdthGM-TJCNTKc.jpg",
"width": 1280,
"height": 720,
"alt": null
}
},
"player_image_large": {
"type": "IMAGE",
"image_value": {
"url": "https://pbs.twimg.com/amplify_video_thumb/975896990835007488/img/X_NdthGM-TJCNTKc.jpg",
"width": 1280,
"height": 720,
"alt": null
}
},
"player_image_x_large": {
"type": "IMAGE",
"image_value": {
"url": "https://pbs.twimg.com/amplify_video_thumb/975896990835007488/img/X_NdthGM-TJCNTKc.jpg",
"width": 1280,
"height": 720,
"alt": null
}
},
"card_url": {
"type": "STRING",
"string_value": "https://twitter.com",
"scribe_key": "card_url"
}
},
"users": {
"878264826199502848": {
"id": 878264826199502800,
"id_str": "878264826199502848",
"name": "API Playground",
"screen_name": "APIPlayground",
"location": "",
"url": null,
"description": "",
"protected": false,
"followers_count": 2,
"friends_count": 0,
"listed_count": 0,
"created_at": "Fri Jun 23 14:53:46 +0000 2017",
"favourites_count": 0,
"utc_offset": -25200,
"time_zone": "Pacific Time (US & Canada)",
"geo_enabled": false,
"verified": false,
"statuses_count": 7,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "F5F8FA",
"profile_background_image_url": null,
"profile_background_image_url_https": null,
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/955114267203833856/QAKctPM__normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/955114267203833856/QAKctPM__normal.jpg",
"profile_link_color": "1DA1F2",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"has_extended_profile": false,
"default_profile": true,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
}
},
"card_platform": {
"platform": {
"device": {
"name": "AdsApi",
"version": "13"
},
"audience": {
"name": "production",
"bucket": null
}
}
}
},
"lang": "en"
},
"request": {
"params": {
"as_user_id": 878264826199502800,
"text": "Video Direct Message Card w/ Four CTAs",
"account_id": "18ce54jkujt",
"trim_user": true,
"card_uri": "card://975910159502454784"
}
}
}