Network lib with google APIs
in
Programming Questions
•
3 years ago
Hi, first post here since I can't seem to find an answer in searches or the docs.
I'm working on a sketch that needs to grab data from google finance for a stock ticker display via arduino. I opened up the basic HTTP client example and modified it but I'm having trouble communicating with google's servers:
I need to connect to and send a POST request with my login info to "https://www.google.com/accounts/ClientLogin" server so I changed the example code to this:
- import processing.net.*;
- Client c;
- String data;
- void setup() {
- size(200, 200);
- background(50);
- fill(200);
- c = new Client(this, "https://www.google.com/accounts/ClientLogin", 80); // Connect to authentication server
- c.write("POST Email=MYEMAIL&Passwd=MYPASSWORD&service=finance&source=arduino-stockticker-alpha"); // Post login data to recieve token back
- }
- void draw() {
- if (c.available() > 0) { // If there's incoming data from the client...
- data = c.readString(); // ...then grab it and print it
- println(data);
- }
- }
But this gives me a java.net.UnknownHostException as well as a nullpoint exception. I'm assuming that's because I'm supposed to connect to a server like "google.com," not a full path like I am trying, and then the nullpoint because the client was never created.
I tried this too:
- c = new Client(this, "google.com", 80); // Connect to authentication server
- c.write("POST /accounts/ClientLogin HTTP/1.0");
- c.write("POST Email=MYEMAIL&Passwd=PASSWORD&service=finance&source=emrich-stockticker-alpha"); // Post login data to recieve token back
and don't get any errors but also don't get a server response at all. Any idea how I'm totally screwing up use of the protocol in this way and how to format things correctly?
As a side note, I'm trying to get into google finance because it'll let give me the data in XML format so I can use processing's XML tools to grab what I need, but suggestions for a better way to get data like this are welcome too!
Thanks for your help,
Stephen
1
