Sign in to follow this  
Followers 0
PaulOBrien

Updating your Twitter status from PHP

6 posts in this topic

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

0

Share this post


Link to post
Share on other sites

Updated to do status post rather than get.

Naughty me!

P

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites
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.

0

Share this post


Link to post
Share on other sites

Try wrapping the message using utf8_encode() function. This works for me when posting an update using PHP and curl.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

MoDaCo is part of the MoDaCo.network, © Paul O'Brien 2002-2016. MoDaCo uses IntelliTxt technology.