daren1212
daren1212

Reputation: 25

Facebook FQLproblem with javascript sdk

Hey everyone,

i do the following query to get a user statuses:

FB.api(
    {
        method: 'fql.query',
        query: 'SELECT message FROM statuses WHERE uid = ' + userId
    },
    function(data) {
        //    do something with the response
    }

);

It works great when the number of result are more than 0.

but when there are no results, the callback function is not called at all.

i need to know if there are 0 rows returning from this query, is there any way to do it?

Thanks :)

Upvotes: 0

Views: 357

Answers (2)

ifaour
ifaour

Reputation: 38135

First of all, the statuses table does not exists. You should be using status table.

The callback is always called but you should properly check against empty objects. Just paste this on the Javascript Test Console:

<fb:login-button scope="read_stream">
    Grant access to statuses
</fb:login-button>

<button onclick="getStatuses()">Get Statuses</button>
<script>
window.getStatuses = function() {
    FB.api(
    {
        method: 'fql.query',
        query: 'SELECT message FROM status WHERE uid = me() AND time < 315532800'
    },
    function(data) {
        if(!isEmpty(data)) {
            for(var key in data) {
                var obj = data[key];
                console.log(obj['message'])
            }
        } else {
            console.log("data is empty")
        }
    });
};

function isEmpty(obj) {
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            return false;
    }

    return true;
}
</script>

Here I am checking for statuses before 1/1/1980 to insure that an empty result is returned. In your console you should note the data is empty response.

Upvotes: 1

Fisch
Fisch

Reputation: 3815

When there are no results from a query, you should be getting an empty array.

Also, there isn't a FQL table named "statuses", it's "status".

Upvotes: 0

Related Questions