-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Direct Message with Media #448
Comments
Looks like you can upload media or a video and then attach that media ID to the DM from twython import Twython
twitter = Twython(APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
# video = open('/path/to/file/video.mp4', 'rb')
# response = twitter.upload_video(media=video, media_type='video/mp4', media_category='dm_video')
image = open('/path/to/file/image.jpg', 'rb')
response = twitter.upload_media(media=image ,media_type='image/jpeg', media_category='dm_image')
media_id = response['media_id_string']
params = {
'event': {
'type': 'message_create',
'message_create': {
'target': {
'recipient_id': '844385345234',
},
'message_data': {
'text': 'Check out this image!',
'attachment': {
'type': 'media',
'media': {
'id': media_id,
}
}
}
}
}
}
twitter.post('direct_messages/events/new', params=params) |
If that doesn't work, let me know. Looks like there is a |
Hi, I've been trying to get this to work and not managed to so far. I've taken the example above and added my keys, tokens etc and the recipient. Has anyone got this working recently? Any help appreciated. Thanks Neale |
I am trying the following
Unfortunately, I am getting back an error
|
I came across this today, and the code above is ok, but before you call api.post() you need to do import json HTH |
Twitter now supports leaving a direct message with a media id
See
https://dev.twitter.com/rest/reference/post/direct_messages/events/new
and
https://dev.twitter.com/rest/direct-messages/attaching-media
Using the api.post function doesn't seem to correctly handle a python dictionary that should be converted to a json object and sent with the post message.
Can you offer an example of the correct way to use api.post? or recommend a different approach?
The text was updated successfully, but these errors were encountered: