Twitter - Simple Post Example

Hello.
I tried to run the Twitter Simple Post.
Apparently the communication take place but then I get the following error

connecting ...
failed : code 0

Any suggestion would be very appreciated.

Regards

More details please:

How are you trying to connect? GPRS? Network shield? Wifi?

Where do we find the sketch (post it here using the code # tags)?

I connect by wi-fi.
The sketch is in the Example directory.
Anyway I’ll post it here.
By the way, I didn’t find the sticker with the MAC address and so I use the one in the example but probably this is not a problem also because I run another example (ho to connect to Google) and It worked.

#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>

// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
// Please uncomment below in Arduino IDE 0022 or earlier.
//#include <EthernetDNS.h>


// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { 192, 168, 2, 250 };

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("2404054267-hKWPVmjP6v0eTvqvTldVDwlFnNEOCkUdcJ");

// Message to post
char msg[] = "Hello, World! I'm Arduino!";

void setup()
{
  delay(1000);
  Ethernet.begin(mac, ip);
  // or you can use DHCP for autoomatic IP address configuration.
  // Ethernet.begin(mac);
  Serial.begin(9600);
  
  Serial.println("connecting ...");
  if (twitter.post(msg)) {
    // Specify &Serial to output received response to Serial.
    // If no output is required, you can just omit the argument, e.g.
    // int status = twitter.wait();
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }
}

void loop()
{
}

might want to hide your token, though

If you try to connect to Twitter at http://api.twitter.com (port 80), you get this message:

SSL is required

The wifi shield library does not support SSL (port 443). Neither does the ethernet shield.

I tried to connect with ethernet cable but nothing changed.
What do you mean that Ethernet Shield doesn't support ... ?

The physical device that you use to connect does not change the protocol required to complete the connection. Twitter requires Secure Sockets Layer encryption. Here is a wikipedia article on it.

The wifi library has no SSL capability. The ethernet library has no SSL capability. You can’t connect and post anything without it.

Thanks.
But what device should I use to post a message by Twitter ?

You need a device that can handle SSL. The ethernet and wifi libraries don't that capability. I don't have any advanced Arduinos to test and I haven't tried with my RPi yet.

I was having this very same issue and it turned out it was the IP address. I had to find my Arduino's IP by following these instructions: http://www.instructables.com/id/Arduino-Ethernet-Shield-Tutorial/step3/Get-started/

To figure out what IP address has been assigned to your board, open the DhcpAddressPrinter sketch. This can be found at:

File --> Examples --> Ethernet --> DhcpAddressPrinter

Once I ran the above example and added that IP to my Simple Post it went right on through to Twitter.

The website that is running the app and where you get your Oauth token takes care of that SSL issue.

Send tweets by Arduino Yun and Yun shield

Work around:

Setup http to https relay server

Workflow:

Arduino->http->'relay server'->https->' Twitter.com'