Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Need help retrieving media from DM #39

Closed
j4p opened this issue Nov 17, 2020 · 2 comments
Closed

Need help retrieving media from DM #39

j4p opened this issue Nov 17, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@j4p
Copy link

j4p commented Nov 17, 2020

Hi,
I just started making a Twitter bot.

Is there any way I can automatically retrieve media from DM and tweet them using this client?
I have managed to retrieve the URL. However, I am not authorized(?) to access it and I am not sure how to exactly do that.

My understanding is that I need to have access to it in order to be able to download it, get the raw binary or base64 encoding of it, and finally upload and tweet it.
Is my understanding correct or is there a better way to do so?

Thank you.

@SimonHoiberg
Copy link
Collaborator

Hi @j4p 👋
Thank you for creating this issue.

Twitter has an unfortunate error response saying that you're not authorized, while in fact, it's like not to be the case.
Most likely there's a problem with how the encoding/decoding works internally.

It's a bug on our side - we will investigate 😊

Thank you.

@SimonHoiberg SimonHoiberg added the bug Something isn't working label Nov 27, 2020
@j4p
Copy link
Author

j4p commented Nov 27, 2020

Hi @SimonHoiberg
Thank you for your response!

Please do not worry too much since I believe this is not a bug in your code but rather simply an incompetence on my end.

First, allow me to explain to you the bot that I am trying to make.
Basically, the bot works by tweeting whatever is sent to it through the DM.
I made the bot with Twitter Account Activity API using the help of Twitter Autohook.
I followed this particular tutorial of which the whole code can be found here.
Everything was great, I only needed to modify the DM response part with a tweet instead.
However, as you might have known, the tweet API endpoint receives query params instead of a JSON object.
Here, I decided to use this client so that I don't have to deal with OAuth signing etc.

So everything went great, but then I decided to implement a feature such that it can also tweet the media attached to the DM.
This is where I am stuck. I managed to retrieve the media URL, however I am not authorized to access it.
Do keep in mind that I am not using the client in this part yet (I only use it for tweeting and plan to use it to upload the attached media later).
I tried making a GET request to the URL with Postman + Authorization header and it worked.
I might be able to do it with the node-fetch module but, again, I don't want to deal with OAuth signing.

So my question is:

  • Can I make a GET request to fetch the image using this client so that I don't have to deal with OAuth signing, or
  • Can I somehow get myself in an "authorized session" using this client so that I can fetch and upload the media right away, or
  • Is there a better way to do what I am trying to achieve (maybe like directly upload the attached media from media URL or media ID using this client)

Afterthoughts
Upon writing this comment I looked back into the full code from the tutorial and decided that I need to look into the Request module.
I avoided using it because it says that it is deprecated.
I will report back to you later on whether it works or not.

Thanks!

Main Project Board automation moved this from To do to Done Jan 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants