Hey guys, this is my first post on this website. Really excited to be a part of you community. I'm a relatively new Arduino user, and I'm trying to create a color-coded mood map of the US based on current twitter search terms. Kind of like the various Twitter mood lamps you've seen on instructables, but geography-based.
I'm having trouble accessing Twitter. I have my authorization key and everything and am currently testing it out using this:
https://dev.twitter.com/oauth/overview/authorizing-requests
I'm using client.print() to make this practice HTTP request, just to see if it'll actually work. Obviously I substituted in my own authorization keys and whatnot.
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="xvz1evFS4wEEPTGEFPHBog",
oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",
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 keep getting this as the message on the serial monitor -->
connecting...
connected
HTTP/1.0 400 Bad Request
content-length: 0
date: Tue, 04 Aug 2015 19:58:49 GMT
server: tsa_a
x-connection-
disconnecting.
Trying to search through explanations but most people are using the Twitter Arduino library, which I read is used for posting tweets, not searching through them. I'm on a bit of a deadline for this project, can anyone help me out? Thanks guys!
Bumping this up because I'd really appreciate some guidance. If you know any recent projects like this you could also link me to it. Thanks y'all!
I'm not expert in http requests, but I suspect the content-length should equal the size of the body (EDIT: which actually is, I checked, 76).
Thanks for responding! I noticed that too -- the content length of the post is 76 -- which is what I sent to the server, but I think the 400 error cuts it off before, so twitter returns zero? Just hypothesizing here ...
I copied and pasted directly from the sample request, but here's what I have.
client.println("POST /1/statuses/update.json?include_entities=true HTTP/1.1");
client.println("User-Agent: OAuth gem v0.4.4");
client.println ("Accept: /");
client.println("Connection: close:");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Authorization: OAuth ");
client.print("oauth_consumer_key="xxxxxxxxxxxxxxxxx", " );
client.print("oauth_nonce="xxxxxxxxxxxxxx", ");
client.print("oauth_signature="xxxxxxxxxxxx", ");
client.print("oauth_signature_method="HMAC-SHA1", ");
client.print("oauth_timestamp="1438732017", ");
client.print("oauth_token="xxxxxxxxxxxxxx", ");
client.println("oauth_version="1.0"");
client.println("Content-length: 76");
client.println("Host: api.twitter.com");
client.println("status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request");
To reiterate, compiles fine but ends up with the 400 error message.
Did you try adding "application/json" to content-type (since I see json in the url)?
Or maybe the url takes json rather the form data?
Does this request work fine from an http client other than arduino?
I get this message back when I try to access twitter API (using the URL you provided):
{"errors":[{"message":"The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.","code":64}]}
https://api.twitter.com//1/statuses/update.json?include_entities=true
Twitter Authorization is required https (SSL) support. Arduino Yun is mandatory.
Thanks for your responses! To respond one at a time: I haven't yet tried this from anything outside an Arduino but I will. I also posted this ? on the twitter forum, and apparently the page hadn't been updated: instead of
POST /1/statuses/update.json?include_entities=true HTTP/1.1
It should've been
POST /1.1/statuses/update.json?include_entities=true HTTP/1.1
to reflect the change in API. Which is why you got that feedback about the API v1 now being inactive.
@florinc not sure what you mean by adding application/json to the content user. I'm still pretty new at this and don't know what the correlation/specification of content-user is, could you elaborate?
Finally, ah that's disheartening to learn about Arduino Yun. Might try double teaming this with a Rasp. Pi. I feel like some newbies are also going to run into this problem so I'll provide some links for whoever looks this up.
http://nodered.org/