Thanks for that, laserlight. Between looking through the various ways to get tokens and continually checking the code from that github code I was playing with, it dawned on me that most of the code from github was dedicated to extracting a temporary token/token-secret for some random twitter user so your app can mess with their account. I also was confused by the fact that the credentials listed on dev.twitter.com under "your access token" for my app were read-only. I tried "recreate my access token" which immediately showed no change. checking back a few minutes later, I saw that I had a new access token and that it was read and write.
All that said, this bit of code is working swell for me now and I have auto-tweeted my first tweet:
//attempt to use locally stored credentials to just tweet to twitter
// Load required lib files
require_once("/var/www/public/twitter/twitteroauth/twitteroauth.php");
require_once("/var/www/public/twitter/config.php"); // this defines all 4 constants used in the constructor in the next command
// Create a TwitterOauth object with consumer/user tokens.
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET);
// if you do not authenticate, you should get a 401 or some HTTP code that is not a 200
// or at least that seems to be the case
$content = $connection->get("account/verify_credentials");
switch ($connection->http_code) {
case 200:
// all good!
break;
default:
die("Twitter auth failed! Bad http code returned from twitter auth: " . $connection->http_code);
}
// Some example calls
//$connection->get('users/show', array('screen_name' => 'abraham'));
$connection->post('statuses/update', array('status' => date(DATE_RFC822))); // i tried this one and it worked
//$connection->post('statuses/destroy', array('id' => 5437877770));
//$connection->post('friendships/create', array('id' => 9436992));
//$connection->post('friendships/destroy', array('id' => 9436992));
switch($connection->http_code) {
case 200:
die("apparently successful?");
default:
die("Bad http record returned by tweet attempt:" . $connection->http_code);
}
Progress!
So I'm wondering if anyone has any thoughts on what might be the best time of day to tweet? I.e., any techniques to sniff out optimal times of day for tweeting for the most exposure.