
This is what I wanted.
1) User clicks on a link which pops up a new window
2) My application would build the update text and include a tiny_url
3) Redirect to Twitter, pre-filling the update field.
In Ruby on Rails, this is what I ended up with. It's not very complicated, so it's probably easier just to see the code. I changed it to a Post model object for this example.
def tweet
@post = Post.find(params[:id])
tiny_url = open("http://tinyurl.com/api-create.php?url=#{url_for(@post)}") {|f| f.read }
message = "#{@post.title} #{tiny_url}"
redirect_to "http://twitter.com/home?status=#{CGI.escape(message)}"
end
There are a lot of good ways to update status on Twitter using the Twitter API, but for this project they were more than I wanted. Here are a few that I plan to check out. I haven't used TwitterAuth yet, and a friend recently brought my attention to the site MessagePub.
I plan to try out TwitterAuth for another feature soon.
If you use the Twitter API, it will automagically use tiny URL for you . . .
ReplyDelete