views:

545

answers:

1

I'm trying to use the Facebook Javascript API to run FQL queries, and it works fine if I try and get users by username or uid, but doesn't work when I'm searching by name.

function get_username()
{
    var name = prompt("Enter name: ")        
      FB.api(
      {
        method: 'fql.query',
        query: 'SELECT username FROM user WHERE name in "'+name+'"'
      },
      function(response) {
          var x = response[0].username
        alert('Username is ' + x);
      }
    );
}

I realize that this will probably return multiple users, but I can't figure out how to tell if it's returning multiple users or no users at all, it seems to freeze after trying to get response[0].username.

I'm probably making a beginner mistake but any ideas?

+2  A: 

Hey,

Check this out: http://developers.facebook.com/docs/reference/fql/user

I don't see a username field. I think that's the issue.

HTH.

Brian
Thanks for pointing that out, and you're probably right that it was an issue, but unfortunately it doesn't work any better if I search for something that's definitely there like uid.
Michael
Can you use IE 8 or firefox with firebug and put a debugging point there, right before you run that code, and evaluate it? Just have it return name (which is indexable, so it should be searchable by name).
Brian
Good idea. I'm getting an Error 102, "Session key invalid or no longer valid" the Facebook error code page (http://wiki.developers.facebook.com/index.php/Error_codes) is not very helpful. When I search by username though it is just returning the proper info, what about searching by name could be triggering an invalid session key?
Michael
That is very odd... I'm not sure, that could be the sign of a bug... alternatively you could try using the users_get rest method and querying the user information that way too... I've not run into this one, so unfortunately, can't be much more help.
Brian

related questions