我从Facebook API中提取专辑照片,然后以砖石风格排列。我设置它以便我将运行API函数,然后当我单击一个按钮它将运行砌体功能,它工作正常。现在我要做的是在下载所有图像后自动运行砌体,如下所示:
function fbAPI() {
//downloading photos and placing them in a div
masonryFunction();
}
function masonryFunction(){
//run the masonry plugin
}
我遇到的麻烦是masonryFunction在fbAPI完成它之前运行良好,这会阻止它工作(所有照片必须先加载)。现在我不能简单地在页面加载时运行masonryFunction,因为fbAPI直到用户输入之后才会启动。我该怎么办?
答案 0 :(得分:0)
在FB登录功能的回调函数中调用fbAPI()函数。
例如,
FB.login(function(response) {
if (response.authResponse) {
facebookLoggedIn();
} else {
alert('User cancelled login or did not fully authorize.');
}
});
function facebookLoggedIn() {
fbAPI();
}
或者,订阅FB auth.statusChange事件:
FB.Event.subscribe('auth.statusChange', function(response) {
facebookStatusChange(response);
});
function facebookStatusChange(response) {
if (response.status === 'connected') {
uid = response.authResponse.userID;
accessToken = response.authResponse.accessToken;
facebookLoggedIn();
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
}