Skip to content

Instantly share code, notes, and snippets.

@semifor
Created September 28, 2018 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semifor/9fc557820308a7dcca485a0adb669e9d to your computer and use it in GitHub Desktop.
Save semifor/9fc557820308a7dcca485a0adb669e9d to your computer and use it in GitHub Desktop.
# Snippet demonstrating how to post a direct message with an attached image
# using the new Twitter direct message API
# First upload the image
my $media = $client->upload_media({
media => [ $image_path_name ],
media_category => 'dm_image'
});
# Attach the image in message_data
my $r = $client->post('direct_messages/events/new', {
-to_json => {
event => {
type => 'message_create',
message_create => {
target => { recipient_id => $user_id },
message_data => {
text => $text,
attachment => {
type => 'media',
media => { id => $media->{id} },
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment