DM with media

dm
restapi
api

#1

API : https://dev.twitter.com/rest/direct-messages/attaching-media

Here we have event json like

{
“event”: {
“type”: “message_create”,
“message_create”: {
“target”: {
“recipient_id”: “844385345234”
},
“message_data”: {
“text”: “Hello World!”,
“attachment”: {
“type”: “media”,
“media”: {
“id”: “12123234234”
}
}
}
}
}
}

With which param name we should generate authorization request header for this json? Any idea? Or no need to include this json to generate authorization header for this endpoint?

FYI : We are writing this json into post body in request.


#2

Hi @RajiitGct,

Assuming your are trying to generate the oauth_signature. I personally use OAuth libs to handle this, but from my knowledge JOSN POST body is not included when generating the oauth_signature for the OAuth1.0a spec. If the POST body included url-encoded query strings (or form-encoded data), those parameters would be included.

Taking a look at python’s oauthlib extract_params, you will see that it will not return params for a JSON string.


#3

You also need to ensure you set a content-type: application/json in your request or it will fail. That is part of your oauth signing request too


#5

Ya, Its correct. Then I tried without including this post body in auth signature. Eventhough I faced “Bad authentication error with code 125”


#6

Sorry, in somewhere in my code, missed out authheader in connect setRequestProperty.Thats the problem.