I finally found the time to look at this again and would like some advice on
I have several twitter tokens and would like to post different things from different accounts depending what is happening at my cottage.
Looking at the twitter.h it shows
Twitter(const char *user_and_passwd);
So I assume I can not redefine the twitter token as it's a const char?
(sorry i'm new to this)
But having played I can redefine the token if I use the demo code and just add the line before it send its twitter message
#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, 1, 150 };
byte mac[] = { 0x00, 0x11, 0x22, 0x33, 0xFB, 0x11 }; // Use your MAC address
byte ip[] = { 192, 168, 1, 80 }; // no DHCP so we set our own IP address
byte subnet[] = { 255, 255, 255, 0 }; // subnet mask
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("Insert your own token here"); // my first twitter token here
// Message to post
char msg[] = "Hello, World! I'm Arduino! @r4rob";
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 ...");
Twitter twitter("Insert your own token here"); // my second twitter token here seems to work ok
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()
{
}
However as soon at I try and be clever and put the tokens inside some if statements it doesn't work
Also is there anyway to print the twitter token so I can play without actually posting
Here is my test code which returned "no token defined" from Google and also the value of account changes.
Sorry if this is basic stuff but i'm managed to make a simple weather station which works well
https://twitter.com/RiceLakeWeather
But I'm at the limit of my knowledge.
Here is my other test code
#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, 1, 177 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter(""); // Empty Status token
int account ;
// Message to post
char msg[] = "Test message @r4rob ";
void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
// or you can use DHCP for automatic IP address configuration.
// Ethernet.begin(mac);
Serial.begin(9600);
}
void loop()
{
account =0;
Serial.println("connecting ...");
Serial.print("Account=");
Serial.println(account);
if (account = 0) {
char msg[] = "This should tweet from first Account @r4rob ";
Twitter twitter("my first token"); // My 1st twitter account
Serial.print("Tweeting Using 0 =");
Serial.println(account);
};
if (account = 1) {
char msg[] = "This should tweet from second Account @r4rob ";
Twitter twitter("my second token"); // My 2nd twitter account
Serial.print("Tweeting Using1=");
Serial.println(account);
};
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.");
}
while(true);
}
The above code returns the following which confuses me as I don't understand how the value of account changes!
Account=0
Tweeting Using1=1
HTTP/1.0 403 Forbidden
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Vary: Accept-Encoding
Date: Thu, 18 Oct 2012 11:18:57 GMT
Server: Google Frontend
Error 403 - token is not specifiedfailed : code 403
Thanks to anyone who takes the time to post.
Rob