Hi, I have a project that checks for and displays the first tweet on a public twitter account. This is just a way of updating the text of an LCD outside my door.
It used the source of the page api.twitter.com/1/statuses/user_timeline.xml?screen_name=arduino&count=1 to extract the tweet. This is the method that was used in the sample Twitter code provided on arduino.cc.
This method is now deprecated. The page now shows the following message "The Twitter REST API v1 is no longer active. Please migrate to API v1.1."
The sample Twitter code on arduino.cc includes the message: "This example doesn't work anymore because the Twitter authentication mode is now different and not compatible with Arduino libraries."
What I'm trying to do now is extract the tweet from the URL that normal Twitter users visit: twitter.com/arduino
The problem is that when I visit the URL from my arduino program, I don't get the same text I see when I look at the source text on my browser (by pressing ctrl+u). I instead get the following:
HTTP/1.1 301 Moved Permanently
date: Fri, 30 Aug 2013 03:01:12 UTC
location: https://twitter.com/arduino
server: tfe
set-cookie: guest_id=v1%3A137783167277866638; Domain=.twitter.com; Path=/; Expires=Sun, 30-Aug-2015 03:01:12 UTC
Content-Length: 0
Connection: close
When I try my code with a different URL, I get the same source text that I see when using a browser.
Does anyone have any idea on how to get the actual source text for the twitter URL?
Here is a simple test program that prints the source of a URL to the Serial monitor. It uses similar code to my current project:
#include <SPI.h>
#include <Ethernet.h>
IPAddress ip(123,456,789,012);
byte mac[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
char serverName[] = "twitter.com"; //CHANGE THIS IF TESTING ANOTHER SITE*******************************
EthernetClient client;
void setup() {
Serial.begin(9600);
Serial.println("Attempting to get an IP address using DHCP:");
if (!Ethernet.begin(mac)) { // if DHCP fails, start with a hard-coded address:
Serial.println("failed to get an IP address using DHCP, trying manually");
Ethernet.begin(mac, ip);
}
Serial.print("My address:");
Serial.println(Ethernet.localIP());
connectToServer();
}
//prints website source one char at a time
void loop()
{
if (client.connected()) {
if (client.available()) {
char inChar = client.read(); // read incoming bytes:
Serial.print(inChar);
}
}
else {
Serial.println("Starting delay between requests.");
client.stop();
delay(120000);
Serial.println("Delay finished.");
connectToServer();
}
}
void connectToServer() {
Serial.println("Connecting to server...");
if (client.connect(serverName, 80)) {
Serial.println("Making HTTP request...\n");
//CHANGE THIS IF TESTING ANOTHER SITE*******************************
client.println("GET /arduino HTTP/1.1");
client.println("HOST: twitter.com");
client.println("Connection: close");
client.println();
delay(1000);
}
else {
Serial.println("Connection to server failed.");
}
}
If anyone has a better way to send text from a smartphone (with an app maybe) to an arduino without using twitter, I'd love to hear it. (A web server won't work since I have no access to the router I'm using). Thanks for the help.