Hello,
Found out today that Twitter will be discontinuing its basic authentication for its API; the push is now towards OAuth but I don’t have a clue as to how to use it or whether it’s the right path for me.
All I want to be able to do is post a tweet linking to the most recently published post when I hit publish. Currently I’m sending the login credentials for my Twitter account as plaintext, which I realise isn’t that secure but as my site is fairly small it isn’t an issue at least for now.
I’m using this basic PHP code:
$status = urlencode(stripslashes(urldecode("Test tweet")));
$tweetUrl = 'http://www.twitter.com/statuses/update.xml';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($curl);
$resultArray = curl_getinfo($curl);
if ($resultArray['http_code'] == 200)
{
curl_close($curl);
$this->redirect("");
}
else
{
curl_close($curl);
echo 'Could not post to Twitter. Please go back and try again.';
}
How do I move from this to an OAuth system? I’d greatly appreciate any tutorials/advice. Thanks in advance.