Hi Ivan,

The jQuery getJSON replaces the trailing "?" with a function name like jsonp4728701093601231 [1]. To test you need to use something more like:

$ curl 'http://twitter.com/users/show/someBadUsername.json?callback=foo'
foo({"request":"\/users\/show\/someBadUsername.json? callback=foo","error":"Not found"})

It looks like the Twitter API is working correctly. One thing to note is that the Twitter API is returning HTTP 404. I am pretty sure the jQuery getJSON method is only calling your function on success (HTTP 200). I'm not totally sure but the jQuery ajaxError event handler may help do what you need.

Thanks;
  — Matt Sanford / @mzsanford

[1] - "jsonp" + currentTimeMillis

On Jan 7, 2009, at 07:48 AM, Ivan wrote:


Hi,

I'm cofounder of Tipjoy - we just made payment on twitter. Check it
out: http://tipjoy.com/twitter

We have a fun project related to this that I'm working on right now.

I'm using jquery to parse the twitter account info from the API.
Disclaimer: I'm learning javascript JIT.

There is either a bug in my javascript, or the return from the twitter
API is wrong.

Here is some simplified code:

$(document).ready(function(){
   var url = "http://twitter.com/users/show/"; + [the username] +
".json?callback=?";
   $.getJSON(url,
       function(data){
           if( data.error ){
               alert("username doesn't exist")
           }
           else{
               alert("that username exists")
           }
       }
   );
});

This code uses jquery's getJSON to grab the account info for a given
username.

The return for a correct username is:
({...});

That wrapping is to pass it to the callback unnamed function.

But this code doesn't work for a username that doesn't exist. The
function doesn't even get called, and the alert doesn't show up.

Putting this is a browser
http://twitter.com/users/show/someBadUsername.json?callback=?

Returns:
{"request":"\/users\/show\/someBadUsername.json?
callback=?","error":"Not found"}

Should that be wrapped in ({...}); ? Is that a bug on twitter's side?

Or is there something I'm doing wrong in jquery?

I looked at the code for this project, and it looks like they are
using jquery to access summize in the same way I'm grabbing from the
twitter api.
http://tweet.seaofclouds.com/
http://github.com/seaofclouds/tweet/tree/master/javascripts/jquery.tweet.js

Any help would be greatly appreciated.

Thanks,
Ivan
http://tipjoy.com

Reply via email to