Secure twitter API

Secure twitter API kann Statusmeldungen von http://twitter.com ändern.

twitter.php

twitter.php
<?php
/* ---------------------------------------- */
// Change these parameters with your Twitter 
// user name and Twitter password.
/* ---------------------------------------- */
$twitter_username = 'username';
$twitter_psw = 'password';
//noch nicht integriert
$myself = 'twitter.php';
/* ---------------------------------------- */
 
/* Don't change the code belove
/* ---------------------------------------- */
require('twitterAPI.php');
if(isset($_POST['twitter_msg'])){
	$twitter_message=$_POST['twitter_msg'];
	if(strlen($twitter_message)<1){
	$error=1;
	} else {
	$twitter_status=postToTwitter($twitter_username, $twitter_psw, $twitter_message);
	}
}
/* ---------------------------------------- */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Secure twitter.com API v0.1</title>
<style type="text/css">
body{font-family:'Lucida Grande', Verdana, sans-serif;; font-size:14px; color:#666666;}
h2{color:#000000;}
h3{color:#000000; font-size:14px;}
p{font-size:12px; color:#333333;}
input{font-size:18px; color:#444444;}
a:link, a:visited, a:hover{color:#0033CC;}
a:hover{text-decoration:none;}
div.footer{padding:6px; border-top:solid 1px #DEDEDE; font-size:10px;}
div.msg{background:#FFFFCC; margin-bottom:10px; padding:4px;}
div.code{padding:10px; background:#FFFFCC; font-size:11px; color:#000000; margin-bottom:20px; width:300px; border:solid 1px #CCCCCC;}
</style>
</head>
 
<body>
<h2>Secure twitter API</h2>
<p>Status Nachricht eingeben:</p>
<!-- This is the form that you can reuse in your site -->
<?php if(isset($_POST['twitter_msg']) && !isset($error)){?>
<div class="msg"><?php echo $twitter_status ?></div>
<?php } else if(isset($error)){?>
<div class="msg">Error: please insert a message!</div>
<?php }?>
<p><strong>What are you doing?</strong></p>
<form action="twitter.php" method="post">
<input name="twitter_msg" type="text" id="twitter_msg" size="40" maxlength="140" />
<input type="submit" name="button" id="button" value="post" />
</form>
<!-- END -->
 
<div class="footer">
For info please visit <a href="https://secure.hellhost.de/wiki/php:stwitterapi">Secure twitter API</a> Original Code by: <a href="mailto:antonio.lupetti@gmail.com">antonio.lupetti@gmail.com</a>
<br />
</div>
 
</body>
</html>

twitterAPI.php

<?php
 
// A simple function using Curl to post (GET) to Twitter
// Kosso : March 14 2007
 
function postToTwitter($username,$password,$message){
 
    $host = "https://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));
 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
 
    $result = curl_exec($ch);
    // Look at the returned header
    $resultArray = curl_getinfo($ch);
 
    curl_close($ch);
 
    if($resultArray['http_code'] == "200"){
         $twitter_status='Your message has been sended! <a href="https://twitter.com/'.$username.'">See your profile</a>';
    } else {
         $twitter_status="Error posting to Twitter. Retry";
    }
	return $twitter_status;
}
?>
Drucken/exportieren
QR-Code
QR-Code Secure twitter API (erstellt für aktuelle Seite)