Direct messages authentication not working after api change - Direct Message Migration


#1

As per the documentation there is a migration which is under progress for direct messages api.
https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/guides/direct-message-migration
I have changed the authentication based on the documentation.
Basically I did 3 changes.

  1. Changed the way we are sending data, it is json payload with recepient id.
    {"event": {"type": "message_create", "message_create": {"target": {"recipient_id": "154810374"}, "message_data": {"text": "Hello World!"}}}}
  2. Header (Content-Type) is changed to application/json
  3. Authorization details as below

Note: I am not giving timestamp/nounce but it is getting generated by postman, tried generating somewhere else and passed it but still no luck.

From apex (salesforce language similar to java) and even from postman I am getting the same error as below:

{
    "errors": [
        {
            "code": 32,
            "message": "Could not authenticate you."
        }
    ]
}

Also looks like api authentication is not updated, it is still using the old way of authentication.
https://developer.twitter.com/en/docs/basics/authentication/guides/authorizing-a-request.html

Please let me know if there is anything which I am missing.


#2

Thanks for writing in!

There are usually a couple of things that trigger this error:

  1. The generated tokens (nonce, timestamp, signature) are not being handled properly.
  2. There is an issue with your Twitter app tokens.

Are you handling your own oauth_signature in this call? You might want to let Postman handle that as well if possible.
I mention this because I typically have Insomnia handle my signature.

We are actively working to revise the authentication section, but to my knowledge, that specific page should still be accurate.