How do I migrate from a basic plaintext password authentication to an OAuth based system?

Posted by different on Stack Overflow See other posts from Stack Overflow or by different
Published on 2010-04-25T14:06:53Z Indexed on 2010/04/25 14:13 UTC
Read the original article Hit count: 198

Filed under:
|
|
|
|

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? Do I need to?

© Stack Overflow or respective owner

Related posts about oauthcalypse

Related posts about oauth