I´m trying to display images from webhook in my app, the result of the webhook is this json:
display_url:‘pic.twitter .com/kCKruHavU…’
expanded_url:‘twitter .com/messages/media/1364334113872781319’
id:1364334107111551000
id_str:‘1364334107111550978’
indices:(2) [1, 24]
media_url:‘ton.twitter .com/1.1/ton/data/dm/1364334113872781319/1364334107111550978/YmPdOAML.png’
media_url_https:‘ton.twitter. com/1.1/ton/data/dm/1364334113872781319/1364334107111550978/YmPdOAML.png’
url:‘t .co/kCKruHavUZ’
but if I get the media_url and put directly in a tag like this, isn´t working
< img src=“ton.twitter .com/1.1/ton/data/dm/1364334113872781319/1364334107111550978/YmPdOAML.png”>
Indeed the url in the navigator says it is not available.
In the documentation says that to view it in a webpage, you should to make this:
< img src=“fetch_dm_image?url=example.jpg”>
But I don´t know how to make the src, what is fetch_dm_image?
Media in direct messages must be retrieved via an authenticated app-user GET request.
in the example, Retrieving media | Docs | Twitter Developer fetch_dm_image is a function that makes the authenticated call in some way on your server side. This is something you’ll have to implement yourself.
1 Like
In Postman I can do it successfully with OAuth 1.0, the result is a file type image, but in code with nodejs the result is something like this:
����JFIFHH��C\naa\n\n\r\r��C\t\t\r\r��R��a��ea��…
How can I convert this to base64 or anything else?
That response from the API is the actual image data, so in node you will need to save this binary stream as an image - i don’t know node that well but there should be a good example somewhere on stackoverflow or something!
1 Like