views:

52

answers:

2

Hello,

I am trying to interact with Twitter via JavaScript. I want to pass a pre-set message to a user's Twitter status page when they click a link. In an attempt to do this, I have a link defined as follows:

<a href="#" onclick="updateTwitterStatus();">Update Status</a>

<script type="text/javascript">
  function updateTwitterStatus() {
    var message = "This is a status update";
    var url = "http://www.twitter.com/home?status=" + escape(message);
    window.open(url, "_blank");
  }
</script>

When I execute this code, I get an encoded message. That shows up like this: This%20is%20a%20status%20update

I have tried decodeUriComponent and encodeUriComponent, but nothing seems to be working. What am I doing wrong?

A: 

The issue is not with the encoding, that is fine. Twitter wants a "+" instead of "%20" for some strange and non standard compliant reason.

Twitter does not allow posting to the status page this way. And this decision makes sense: After logging into twitter, you surely don't want to give any website you visit the possibility to spam your feed.

You might want to have a look at http://dev.twitter.com/pages/libraries#javascript

nhnb
Not true. Twitter DOES allow posting this way - for the currently logged on user.
Pekka
Twitter does not allow posting to the status page this way for the reasons stated in my answer. All it does is open the edit page and put the text into the text area. You might want to try it out: http://www.twitter.com/home?status=This+message+is+not+posted+to+my+status+page+unless+I+click+on+Tweet.
nhnb
Posting or preparing to post, I meant the same thing. Anyway, good call! I can't upvote any more but removed the downvote.
Pekka
+1  A: 

Have you thought using the twitter api? http://apiwiki.twitter.com/Twitter-API-Documentation

txwikinger