I am using the Facebook JavaScript SDK.
I have created two fan pag开发者_高级运维es on Facebook using my Facebook id, and now I want to get those pages via JavaScript. How can I do this with the Facebook JavaScript SDK?
you can query that via graph api via '/me/accounts'
Following the photo-albums example, this is a quick sample code:
<html>
<head>
<title>My Pages list</title>
</head>
<body>
<fb:login-button perms="manage_pages"
onlogin="getPages()">
Grant Permissions to Allow access to Pages</fb:login-button>
<ul id="pages"></ul>
<script>
window.getPages = function() {
FB.api('/me/accounts', function(resp) {
var ul = document.getElementById('pages');
for (var i=0, l=resp.data.length; i<l; i++) {
var
page= resp.data[i];
li = document.createElement('li');
li.innerHTML = "Name: " + page.name + "<br /> Category: " + page.category;
ul.appendChild(li);
}
});
};
</script>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'APP_ID_HERE', cookie:true,
status:true, xfbml:true
});
</script>
</body>
</html>
The page
object contains the following fields: name
, id
, category
and access_token
精彩评论