2012-06-29 51 views

回答

2

如果使用Facebook JS SDK可以初始化之後做到這一點FB對象

FB.api('/the_fanpage_path', function(response) { 
     if(response.is_published) { 
     // it is a Fan Page! 
     } 
    }); 
3

如果您使用jQuery並可以找出這些頁面的URL的模式,您可以使用jQuery.get來檢查它們是否存在。如果你不使用jQuery,你可以用原始的XmlHttpRequests做同樣的事情。

例如,如果URL爲「www.facebook.com/fanpage/{{username}}」,你可以這樣做:

function startCheckForFanPage(username) { 
    $.get("www.facebook.com/fanpage/" + username, function(response) { 
     // if response.showsThere'sAPageThere, do X 
     // otherwise, do Y 
    } 
} 
+0

不幸的是,我得到一個「同源策略」錯誤與此解決方案。 – e3matheus

+1

有辦法來處理,這個鏈接應該很有幫助http://www.kendoui.c​​om/blogs/archive/11-10-03/using_cors_with_all_modern_browsers.aspx – machineghost

1

如果您不想加載FB SDK,那麼您可以爲例如一個AJAX獲取請求。 http://graph.facebook.com/facebook。這與交叉來源策略一起工作,因爲graph.facebook.com允許不同的域。

的響應是JSON所以像這樣的工作:

function startCheckForFanPage(username) { 
    $.get("graph.facebook.com/" + username, function(response) { 
     if (response) 
     // otherwise, do Y 
    }, function() { 
     // Handle 404 or other failures here 
    }) 
} 

編輯:這不再起作用