I have a web app registered in Twitter and so have an app ID. I want to use that to publish content from the website to the users' timeline (on their behalf, their own content). I have it working on the server side but I'd like to know the way with jQuery to do it on client side.
1 Answers
With jQuery, use the jQuery.post() method. Something like this should work:
$.post("/myTwitterUpdater.php",
{ 'status': 'Hello world!' });
This is assuming that on the server side your script is named myTwitterUpdater.php
and it accepts the status update in a parameter named status
. Add your own authentication mechanisms as additional parameters or something on top of that, if you need that. The server should then use the Twitter REST API and more precisely its POST statuses/update resource to forward your status update to Twitter. (You said you got it working already, but for anyone else interested, just Google for "twitter oauth php example", or substitute PHP with your language of choice.)
Twitter's OAuth-authentication is best left for the server to handle. It's difficult to do with JavaScript but not impossible.
-
you mean there's no need to use the app id, the user's token...? – Bastian May 17 '12 at 11:52
-
I mean an oauth signed request – Bastian May 17 '12 at 15:11
-
Yes, you do need to use the OAuth mechanism. However, with JavaScript it's apparently difficult but not impossible. (Disclaimer: I haven't actually used the parts of the Twitter API that need authentication, only those that don't.) I've revised my answer, please read it again. – ZeroOne May 17 '12 at 18:34
-
ok, the answer looks better now and convinced me not to do it actually :) – Bastian May 18 '12 at 06:49