Failed to send DM by new API


#1

We failed to send DM with new API, while succeeded using old one with same --consumer-key and --consumer-secret .

New API

$ twurl -H "api.twitter.com" -XPOST "/1.1/direct_messages/events/new.json" -d '{"event": {"type": "message_create", "message_create": {"target": {"recipient_id": "240733411"}, "message_data": {"text": "Hello World!"}}}}' | jq .
{
  "errors": [
    {
      "code": 32,
      "message": "Could not authenticate you."
    }
  ]
}

Old API

$ twurl -H "api.twitter.com" -XPOST "/1.1/direct_messages/new.json?text=hello&screen_name=wifecooky" | jq .
{
  "id": 1013593889322614800,
  "id_str": "1013593889322614788",
  "text": "hello",
  "sender": {
    "id": 870127656477483000,
    "id_str": "870127656477483008",
    "name": "Hottolink_AG",
    "screen_name": "hottolink_ag",
...

#2

The id 240733411 is for @wifecooky .

$ twurl -H "api.twitter.com" -XGET "/1.1/users/show.json?screen_name=wifecooky" | jq .
{
  "id": 240733411,
  "id_str": "240733411",
  "name": "wenping wang",
  "screen_name": "wifecooky",
...

#3

You’re sending a JSON encoded value to the API, so you need to specify this on the twurl command.

Try adding -A "Content-Type: application/json" to the first command.


#4