FeedHive/twitter-api-client

`directMessagesEventsNewMessageCreate` is not sending the good query

lcswillems opened this issue · 4 comments

This code:

await twitterClientRef.current.basics.oauthAccessToken({
        oauth_verifier: "XXXXX",
});

sends this kind of request:

fetch("https://api.twitter.com/1.1/direct_messages/events/new.json", {
  "headers": {
    "accept": "*/*",
    "accept-language": "en-US",
    "authorization": "OAuth oauth_consumer_key=\"XXXXXX\",oauth_nonce=\"XXXXXX\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"XXXXXX\",oauth_token=\"XXXXXX\",oauth_version=\"1.0A\",oauth_signature=\"XXXXXX\"",
    "content-type": "application/x-www-form-urlencoded",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "cross-site",
  },
  "referrer": "http://localhost:3000/3",
  "referrerPolicy": "no-referrer-when-downgrade",
  "body": "id=908597870&data=test",
  "method": "POST",
  "mode": "cors"
});

However, the documentation says this:

Requires a JSON POST body and Content-Type header to be set to application/json. Setting Content-Length may also be required if it is not automatically.

But also that the body should be the following object:

{"event": {"type": "message_create", "message_create": {"target": {"recipient_id": "RECIPIENT_USER_ID"}, "message_data": {"text": "Hello World!"}}}}

I think there is an issue with the lib, isn't it?

Ahh, nice catch!
I'll look into this asap.

Hi @SimonHoiberg , thanks a lot for the time you took! Have you tested if it works now? Because, from the modifications, the content-type has changed but not the data sent to Twitter, which was also a problem.

Hi @lcswillems
Thank you for pointing this out.

I've given the whole direct-messages endpoints an overhaul.
This includes some breaking changes.

Please refer to this PR to see:
#53

But it works now 🙌

Great!!! Thank you for this fix!