POST statuses/update formatting uri


#1

I’m trying to post to twitter using the API, and I already have my 4 keys from my app and account. I can post simple messages (strings containing no special characters). When I try to post the following message: Maybe he’ll finally find his keys. #peterfalk, I get a 401 saying that it couldn’t authenticate me. I’ve been comparing to twitter4J and the oauthBaseString is the same:

POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%[mykey]%26oauth_nonce%3D3898605892584130366%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1501185867%26oauth_token%[mytoken]%26oauth_version%3D1.0%26status%3DMaybe%2520he%2527ll%2520finally%2520find%2520his%2520keys.%2520%2523peterfalk

Here is what my Authorization header looks like:

OAuth oauth_consumer_key=[mykey],oauth_nonce=3898605892584130366,oauth_signature_method=HMAC-SHA1,oauth_timestamp=1501185867,oauth_token=[mytoken],oauth_version=1.0,oauth_signature=I6AGkpSgiF90R8jf2C6vt5RfMgw%3D

and the Uri:
https://api.twitter.com/1.1/statuses/update.json?include_entities=true&status=Maybe%20he'll%20finally%20find%20his%20keys.%20%23peterfalk

Any thoughts on how I can correct this problem?
My code works if I have a simple message such as “HelloWorld”


#2

You should never be including OAuth parameters as URL parameters in the API call.


#3

I’m a bit confused, how would I specify the status to post then?


#4

Status is a valid parameter. Oauth tokens are not. They go in the header not in the URL.


#5

Wait… Sorry. It’s late here and maybe I’m confused and not reading correctly. You said the baseString. Apologies! I’ll dig in more tomorrow to check I understand the issue better :slight_smile:


#6

Ok thanks, I might not have been clear. But I am putting the OAuth … as the value for the Authorization header.


#7

You were clear - I read too fast on my commute - my bad. Bear with me (or anyone else who can dive in to suggest what might be up in the meantime!)


#8

I ended up getting this to work by putting my status in the body instead of the URL as a parameter. Set content type to application/x-www-form-urlencoded.