How can I download a media from a direct message using the API?
Anyone have this problem?
Hi @cadu_bressan, media within direct messages will always require user authentication. Obviously, a user can view this media with an authenticated Twitter.com session. In order for your application to display this media on behalf of the user, you will need to request the media by signing an OAuth request with the user’s access token.
Downloading DM attached images
Is there curl command or API call to retrieve image from ton.twitter.com URL?
Hi @jbulava, the user’s access token is what I get after the “account/verify_credentials.json” method, correct?
So, which method I have to use to display the media without being authenticated on Twitter.com?
I already have the ID of the DM and the ID of the media entity.
I’m not the best person to answer OAuth questions, but you should be able to get a user’s access token when they go through your application authentication process. This overview may be helpful depending on how users are accessing your app.
There is no API method to display the media; simply make a direct request to the URL of the media (e.g.
entities.media.expanded_url) and add an auth header with the owner’s access token.
It works, thanks a lot!
Awesome. Glad I could help!
can someone please write an example say if i have the access_token and i have the url what should i be sending?
i am using python and i have an authenticated session but i keep getting 302 and than 401 on the requested url
You have to send the OAuth authentication in the header of the request.
I’m trying to get one image using an Authorization header but its still returning 401 Error.
Its still not working, I have tried with Authorization header.
curl -v --get ‘https://twitter.com/messages/media/910689064256286724’ --header twapi
twapi: Authorization: oauth_consumer_key=“xxxx”, oauth_nonce=“a6a464a6f8d2549f”, oauth_signature=“xxxx%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1505969588”, oauth_token=“22222222-dddxx”, oauth_version="1.0"
<html><body>You are being <a href="/login?redirect_after_login=%2Fmessages%2Fmedia%2F910689064256286724">redirected</a>.</body></html>
Any help is appreciated.
Hi, I’m getting a 200 back, but it is the login page - were you able to get this working?
Hi, I’ve not been able to download media addressed to me using oauth either. I’m using the following:
curl -X GET \ https://twitter.com/messages/media/930439608738959366 \ -H 'authorization: OAuth oauth_consumer_key=\"redacted\",oauth_token=\"redacted\",oauth_signature_method=\"redacted\",oauth_timestamp=\"redacted\",oauth_nonce=\"redacted\",oauth_version=\"1.0\",oauth_signature=\"redacted\"' \ -H 'cache-control: no-cache' \ -H 'postman-token: 4c76b345-846d-eb0a-84bf-97c54fbdf0dd'
The oauth credentials are OK - I can swap out the url above for https://api.twitter.com//1.1/account_activity/webhooks.json and it will work and return the webhooks. It seems you can’t retrieve DM media using the same oauth that sets up the webhook…? I cant get this to work in my hosted webhook processing, or via POSTMAN.
Anyone been able to get this working?
No not working it yet!
@cadu_bressan Unfortunately I can’t make it work. Can you please post a snippet of code/command how you got it worked?
I’m going to close this topic since it is quite old and we have had changes to the API since its original posting. If you are still experiencing difficulties with this, please post a new topic and include as many details as possible about your specific situation.