Guest Paul (MVP) Posted December 14, 2006 Report Posted December 14, 2006 For one of the interesting projects i've been working on, i've needed to update my Twitter status from within a PHP script... and I thought the code to do it (that uses the Twitter API) might be of interest to others... so here it is :) <?php $email = $_GET['email']; $password = $_GET['password']; $status = urlencode( $_GET['status'] ); $url = "http://8.7.217.31/statuses/update.xml"; $session = curl_init(); curl_setopt ( $session, CURLOPT_URL, $url ); curl_setopt ( $session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); curl_setopt ( $session, CURLOPT_HEADER, false ); curl_setopt ( $session, CURLOPT_USERPWD, $email . ":" . $password ); curl_setopt ( $session, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $session, CURLOPT_POST, 1); curl_setopt ( $session, CURLOPT_POSTFIELDS,"status=" . $status); $result = curl_exec ( $session ); curl_close( $session ); echo( $result ); ?>[/code] Simple but effective :D P
Guest Paul (MVP) Posted February 19, 2007 Report Posted February 19, 2007 Updated to do status post rather than get. Naughty me! P
Guest Jaakko Posted February 20, 2007 Report Posted February 20, 2007 Hi, I have also played with similar php twitter uploader script but I encountered a problem when using scandinavian characters like ä or ö. I've encoded the status message characters with the url encoder like this: $status = urlencode ($status); However, it doesn't work. The status text which appears in the twitter site is cut from the first scandinavian character. Has someone any proposals how to make this work or is this a bug on twitter side? Jaakko
Guest Paul (MVP) Posted February 20, 2007 Report Posted February 20, 2007 Assuming the $status variable is intact when you go into that line (worth checking), then the urlencode should fix it AFAIK, so perhaps it is something odd Twitter are doing. I'd suggest dropping them a mail, they're generally pretty good at replying ;) P
Guest Jaakko Posted February 20, 2007 Report Posted February 20, 2007 Assuming the $status variable is intact when you go into that line (worth checking), then the urlencode should fix it AFAIK, so perhaps it is something odd Twitter are doing. I'd suggest dropping them a mail, they're generally pretty good at replying ;) P Ok, I submitted a request via contact page. I'll let you know if they respond.
Guest dropkernel Posted March 4, 2007 Report Posted March 4, 2007 Try wrapping the message using utf8_encode() function. This works for me when posting an update using PHP and curl.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now