Facebook JavaScript SDK for FQL with additional pa

2019-02-07 11:23发布

问题:

Facebook deprecated FB.Data.waitOn and FB.Data.query and they recommend we use FB.api instead.

More info: http://developers.facebook.com/blog/post/561/

This sounds easy enough, but I can't seem to pass additional parameters with my FQL request without getting an error from Facebook. For example, I can successfully do this:

FB.api({
    method: 'fql.query',
    query: 'select page_id, name, pic, page_url from page where page_id=' + some_page_id
}, function(response){
    console.log(response);
});

But I'd also like to pass the 'return_ssl_resources=1' additional parameter so that Facebook returns secure resources instead of non-secure ones. However, if I try the following, Facebook returns a "Parser error: unexpected '&' at position 71" error:

FB.api({
    method: 'fql.query',
    query: 'select page_id, name, pic, page_url from page where page_id=' + some_page_id + '&return_ssl_resources=1'
}, function(response){
    console.log(response);
});

Does anyone know how to pass additional parameters when making FQL requests using the JavaScript SDK?

回答1:

It turns out that we can pass additional parameters as properties in the first argument to FB.api():

FB.api({
    method: 'fql.query',
    query: 'select page_id, name, pic, page_url from page where page_id=' + some_page_id,
    return_ssl_resources: 1
}, function(response){
    console.log(response);
});