Facebook Javascript API,回调函数?
我在我的jQuery Mobile Website
使用Facebooks Javascript API
来导入facebook page
的albums
和photos
。
它相当容易使用API:
window.fbAsyncInit = function() { // init the FB JS SDK FB.init({ appId : 'YOUR_APP_ID', // App ID from the app dashboard channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms status : true, // Check Facebook Login status xfbml : true // Look for social plugins on the page }); // Additional initialization code such as adding Event Listeners goes here FB.api('16907099963/albums', checkForErrorFirst(getAlbums)); }; // Load the SDK asynchronously (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));
如你所见,我在这里调用API: FB.api('16907099963/albums',checkForErrorFirst(getAlbums));
这将给我这个页面的所有专辑。 该调用是asynchronous
。 我需要找到一种能够知道通话何时完成的方法。 但我真的找不到任何callback functions
..
API可以在这里找到
我要求这个的原因是,我需要添加一个jquery移动“加载”小部件,然后我调用API并使其在专辑渲染时停止。 对这一个有什么想法吗?
checkForErrorFirst
是回调函数。 我想你在FB.api
的页面ID之前也缺少斜杠。 如果您无法编辑checkForErrorFirst
函数,请快速解决:
loader.show(); FB.api('/16907099963/albums', function(result) { loader.hide(); checkForErrorFirst(getAlbums)(result); });