0

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?

2
  • 1
    encodeURIComponent should do the job. The status is getting garbled inside twitter? Commented Jul 3, 2010 at 12:36
  • I think your code is correct. Are you sure it isn't Twitter replacing your spaces? Commented Jul 3, 2010 at 12:39

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

3 Comments

Not true. Twitter DOES allow posting this way - for the currently logged on user.
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: twitter.com/….
Posting or preparing to post, I meant the same thing. Anyway, good call! I can't upvote any more but removed the downvote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.