I am having a couple of issues when trying to use the Direct Message endpoint (https://api.twitter.com/1.1/direct_messages/new.json) from a Java application. Before anyone recommends it, I do not have the option to use any libraries to make the call, I must do this directly myself.
For both issues, the cause appears to be around the encoding of the actual message itself. I either encode correctly (as far as I can tell) but then authorization fails, or I encode incorrectly and authorization succeeds (but then the message sent is not decoded correctly).
In both cases I want to send the string “This is a:test” (yes, with semi-colon).
In both cases my authentication (“Authorization” header) has not changed. Only the encoding of the message parameter (“text”) has changed.
First Issue - Correct encoding, authorization fails
If I encode the above string to “This%20is%20a%3Atest” then I receive 401 (“Authorization Required”) error.
Second Issue - Incorrect encoding, authorization succeeds
If I encode the above string to “This%2520is%2520a%253Atest” (effectively encoding it twice) then the Direct message is sent, but the recipient receives “This%20is%20a%3Atest”. This appears to have been decoded once (which is what I would expect).
Has anyone seen this before? Does anybody have a pure Java example of hitting this endpoint?
Any help would be very much appreciated.