500 Internal Server Error when trying to Update Twitter Status

1 view
Skip to first unread message

Alex

unread,
Nov 20, 2009, 7:32:32 PM11/20/09
to Twitter Development Talk
Hi,

I made a simple script to update a twitter status. I worked fine with
GET, but I know it would be stupid to use that because it sends
username and password in the url. I tried changing it to POST, and I
keep getting a 500 Internal Server Error whenever I try to use it.

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Here's my html:

<html>
<head>
<script type="text/javascript">
var xmlhttp = new XMLHttpRequest();
function login() {

if (xmlhttp==null) {
alert("Your browser doesn't support XMLHTTP!");
}

var url="twitupdate.php";
var params="u=username&p=password";
xmlhttp.open("POST", url, true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange = function() {//Call a function when the
state changes.
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
}

xmlhttp.send(params);
}

function stateChanged() {
if (xmlhttp.readyState==4) {
alert(xmlhttp.resonseText);
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
</script>
</head>
<body>
<input type="text" id="username" />
<input type="text" id="password" />
<input type="button" onclick="login()" value="Login"/>
</body>
</html>

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Here's My PHP:

<?php
$tweettext = $_POST["
require "Twitter.class.php";

$tweet = new Twitter($_POST["u"], $_POST["p"]);

$success = $tweet->update("yay!");
if ($success) echo "Tweet successful!";
else echo $tweet->error;

?>

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Thanks,

Alex
Reply all
Reply to author
Forward
0 new messages