Simple way to add "What are you doing?" update box to a site

2 views
Skip to first unread message

drupalot

unread,
Nov 3, 2008, 3:01:38 PM11/3/08
to Twitter Development Talk
In your opinion, what is the easiest way to add the "What are you
doing?" update box to a site? For starters, it's okay for me if the
update box is tuned to just one account.

Admittedly, I'm pretty much a non-developer that is decent with Drupal
and just starting to learn php, but am working on a project with a
friend that would require adding the Twitter update box to just one
page. If there is a way to embed the box as a widget through html or
php into a page, that would be ideal. Or if there are step-by-step
instructions for the full API I might be able to swing it, but not
sure I can tell from the API how that's done at this point. So far,
what I've found in the API is the following, and I'm embarrassed to
say I'm not sure how to do it with just these instructions:

Post a status update, authenticated: curl -u email:password -d
status="your message here" http://twitter.com/statuses/update.xml


Any thoughts for a newbie?

Alex Payne

unread,
Nov 3, 2008, 7:55:14 PM11/3/08
to twitter-deve...@googlegroups.com
If you can hold on for a week or so, we're about to release a nifty
new version of our drop-in widgets. The widget allows users to update
and much more.

--
Alex Payne - API Lead, Twitter, Inc.
http://twitter.com/al3x

drupalot

unread,
Nov 4, 2008, 12:54:29 PM11/4/08
to Twitter Development Talk
Thanks, I really look forward to that.

Meanwhile as a placeholder I have an interim super-simple box that
looks like it's almost working. Could you glance at this snippet and
perhaps let me know what I'm missing if it's something obvious?

<FORM ACTION="http://twitter.com/statuses/update.format"
METHOD=POST>Your tweet:<BR> <TEXTAREA NAME="tweet" COLS=40 ROWS=6></
TEXTAREA> <P><INPUT TYPE=SUBMIT VALUE="submit"> </FORM>

I would like to pass username and password as well if there's a quick
line of simple html for that?

Thanks, and once again please forgive me my newbie-ness on this.

Alex Payne

unread,
Nov 4, 2008, 4:08:05 PM11/4/08
to twitter-deve...@googlegroups.com
The way a number of sites do this is to provide an input box that then
posts to our logged-in user home page with the "status" parameter
filled out with what the user typed on the referring site. This HTML
would do the trick:

<form action="http://twitter.com/home" method="get">
<textarea name="status">tweet goes here</textarea>
<input type="submit" value="update" />
</form>

Good luck!

fumbler

unread,
Nov 6, 2008, 12:00:03 AM11/6/08
to Twitter Development Talk
Thanks. That pre-populates the Twitter status box after asking the
user to log in. What I'm trying to do is to post directly to Twitter,
and skip the login screen by passing the user/pass along with the post
if possible, since it will always be the same user anyway the user
pass can be hardcoded into the snippet. Is there an easy way to do
that? Either way, look forward to your new drop-in widget but hope to
continue exploring this route in the meantime. Thanks!

Alex Payne

unread,
Nov 6, 2008, 1:47:28 AM11/6/08
to twitter-deve...@googlegroups.com
There's not a particularly easy way to do that using just client-side
HTML and JavaScript, no.

drupalot

unread,
Nov 7, 2008, 1:53:41 PM11/7/08
to Twitter Development Talk
Thanks Alex. After looking into this further, I eventually found the
following PHP/curl snippet that seems to plug into the status update
API very well and do what I was trying to do. I tested it and it
works, even authenticates, but lacks the actual html text area where
the user (really just me) would enter the text to post from a web
page. (Instead it just has a default message on the "$message =" line
below so always posts the same message to Twitter) I think it's a
simple matter of placement of the html snippet for a text area. Would
you agree? If so, where in your opinion would I insert a vanilla text
area in or around this code below? Thanks for your patience with me on
this.

<?php
// Set username and password
$username = 'username';
$password = 'password';
// The message you want to send
$message = 'is twittering from php using curl';
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if (empty($buffer)) {
echo 'message';
} else {
echo 'success';
}
?>

Alex Payne

unread,
Nov 8, 2008, 2:41:45 PM11/8/08
to twitter-deve...@googlegroups.com
It seems like you'd want to make this snippet of PHP grab its
variables from POST data, and then have a form similar to the one I
suggested POST to that location of this script.

drupalot

unread,
Nov 8, 2008, 8:59:33 PM11/8/08
to Twitter Development Talk
Thanks Alex. I should be able to wrap up that snippet now. Once again,
I appreciate your patience with me and help here.
Reply all
Reply to author
Forward
0 new messages