FeedHive / twitter-api-client

A user-friendly Node.js / JavaScript client library for interacting with the Twitter API.
MIT License
948 stars 84 forks source link

`directMessagesEventsNewMessageCreate` is not sending the good query #45

Closed lcswillems closed 3 years ago

lcswillems commented 3 years ago

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?

SimonHoiberg commented 3 years ago

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

lcswillems commented 3 years ago

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.

SimonHoiberg commented 3 years ago

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: https://github.com/FeedHive/twitter-api-client/pull/53

But it works now 🙌

lcswillems commented 3 years ago

Great!!! Thank you for this fix!