1

UPDATE 2

SOLVED, I was missing Header String tutorial instructions at https://developer.twitter.com/en/docs/basics/authentication/guides/authorizing-a-request.html

Answer to my question: Headers must not contain any json data.

Here's my fully functional project, just insert your credentials and you are ready to send Twitter direct messages: https://github.com/ricarrrdo/gs-rest-service

Note: I'm using Spring deprecated AsyncRestTemplate, so if someone knows how to use the new WebClient, please upgrade restASyncClientBody() method inside Application.java - it would be much appreciated!

UPDATE 1

https://github.com/ricarrrdo/gs-rest-service/blob/master/src/main/java/hello/Application.java#L2-L12

This link above is my spring boot project which recreates Twitter given example at https://developer.twitter.com/en/docs/basics/authentication/guides/creating-a-signature.html to authenticate and authorize a API request. It's working fine, just compile/run with mvn spring-boot:run and watch console output. You can check lines 41-52, which are the same parameters used in Twitter example.

Problem/Question

I'm trying to send a Direct Message on Twitter via Twitter API but I keep getting Bad Authentication data error. How should I change my code to be able to send direct messages?

I mean: In https://developer.twitter.com/en/docs/basics/authentication/guides/creating-a-signature.html there's an example with how to create a valid Oauth header using x-www-form-urlencoded parameters. But how can I create valid Oauth headers when sending Json?

Twitter tutorial for direct messages here - https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event

Notes

Authorization header needed to send a direct message:

authorization: OAuth oauth_consumer_key="YOUR_CONSUMER_KEY", oauth_nonce="AUTO_GENERATED_NONCE", oauth_signature="AUTO_GENERATED_SIGNATURE", oauth_signature_method="HMAC-SHA1", oauth_timestamp="AUTO_GENERATED_TIMESTAMP", oauth_token="USERS_ACCESS_TOKEN", oauth_version="1.0"

riccor
  • 11
  • 1
  • 4
  • Can you please explain more? what do you mean by Answer to my question: Headers must not contain any json data? The header you provided is not a json format. – Dohab Jun 10 '22 at 06:37

0 Answers0