Twitter's Example Code not working on Arduino

arduino
api

#1

Hey guys, I’m new to the Twitter-Development-verse. I’m working on a mood light project with Twitter & Arduino and was testing my authorization key with the sample HTTPS request Twitter had here:

POST /1/statuses/update.json?include_entities=true HTTP/1.1
Accept: */*
Connection: close
User-Agent: OAuth gem v0.4.4
Content-Type: application/x-www-form-urlencoded
Authorization: 
        OAuth oauth_consumer_key="xvxxxxxxxxxog", 
              oauth_nonce="kYjzxxxxxxxx4cg", 
              oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D", 
              oauth_signature_method="HMAC-SHA1", 
              oauth_timestamp="1318622958", 
              oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", 
              oauth_version="1.0"
Content-Length: 76
Host: api.twitter.com

status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21

I used client.println() to send these to the server, but I keep getting this in response:

HTTP/1.0 400 Bad Request
content-length: 0
date: Tue, 04 Aug 2015 19:58:49 GMT
server: tsa_a
x-connection-

Very confused – I used my own authorization keys from the ‘Test OAuth’ option we have, instead of the sample code’s, but outside of that it’s just a sample request. Hoping to springboard off of this to my own code so I can search for terms instead of posting tweets, but first, I’m really stuck on why this isn’t working. Any help?


Arduino WiFi Twitter Read Only, App Read Permission
#3

I’ve just spotted that the “Creating a signature” page refers to /1/statuses/update.json, which is no longer valid - should be /1.1/ - we need to fix that.


#4

Hi, thanks for your response! That’s definitely something any person who’s trying my approach should know in advance. However, I fixed that error and am still getting the same 400 Bad Request message sent back. :confused: Any ideas?


#5

There are a bunch of things that can cause issues with OAuth, annoyingly. One example is that the time on the client and server needs to be very closely in line, or the server will reject the signature.

From the output of the command you posted in the original post, it looks like the response itself is truncated. Are you calling Twitter over HTTPS? I wasn’t sure that was possible from an Arduino?

Most (if not all) Arduino->Twitter scenarios I’ve worked on in the past have used something more capable upstream of the Arduino to do the actual call to Twitter, using one of the common open source client libraries. I had another similar discussion recently where I recommended a tool like Node-Red for doing the Twitter OAuth and update.