*I* am not posting the user's credentials, the browser is. And I've
never had to know how. the statuses/friends_timeline and statuses/
mentions calls have always just worked with no need for me to fiddle
with credentials in the JavaScript.
I've learned that problem can be fixed by inserting the line
$.post("http://twitter.com/statuses/update.json", { status: ""});
just before the getJSON line. Doing so makes the statuses/show call
return the proper favorited value, and it doesn't create a new tweet
because Twitter ignores blank tweets. But this seems very kludgy, and
I'd like to know how to do it right.
On Apr 16, 2:28 pm, Chad Etzel <[email protected]> wrote:
> How are you posting the user's credentials to the
> /favorites/(create/destroy) calls? And how are you avoiding the
> cross-domain ajax limitation?
> -Chad
>
>
>
> On Thu, Apr 16, 2009 at 2:35 PM, Dr. Drang <[email protected]> wrote:
>
> > I'm writing a Twitter webapp using jQuery. One of the features is the
> > ability to toggle the Favorite status of a tweet. The function looks
> > like this:
>
> > function toggleFavorite(msg_id) {
> > $.getJSON("http://twitter.com/statuses/show/" + msg_id + ".json",
> > function(data){
> > if (data.favorited) {
> > $.post('http://twitter.com/favorites/destroy/'+ msg_id +
> > '.json',
> > {id:msg_id},
> > function(post_return){
> > $('#msg-' + msg_id + ' a.favorite').css('color', 'black');
> > }
> > );
> > }
> > else {
> > $.post('http://twitter.com/favorites/create/'+ msg_id +
> > '.json',
> > {id:msg_id},
> > function(post_return){
> > $('#msg-' + msg_id + ' a.favorite').css('color', 'red');
> > }
> > );
> > }
> > }
> > );
> > }
>
> > This used to work fine. But recently (I don't know when it started and
> > I don't know whether it's due to a change in the API or a change I
> > made elsewhere in my code) the "favorited" field began to always
> > return false, even if the tweet had been favorited by the user. The
> > getJSON call seems to be behaving like
>
> > curlhttp://twitter.com/statuses/show/msg_id.json
>
> > instead of
>
> > curl -u user:passwordhttp://twitter.com/statuses/show/msg_id.json
>
> > Is there some way to incorporate the user's Twitter ID into the
> > getJSON call to statuses/show?