May 2011
Beginner
408 pages
10h 27m
English
If I take all the examples that I wrote previously and put them in one index.html file, it looks this:
<html>
<head>
<script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="fb-root_18_chapter-07"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}()); FB.Event.subscribe('auth.sessionChange', function(response) { if (response.session) { var query = FB.Data.query('SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = {0}) AND is_app_user = 1', user_id); query.wait(function(friends) { for (i=0; i++; i<friends.length) { // add the friend to your database as a friend // (assumes we can get the user id of current user through the session) $.post('/add_friend',{'id': friends[i].uid}); $("#friends").append("<img src='http://graph.facebook.com/"+friends[i]. uid+"/picture' width='50' height='50' />"); } $.post( '/get_cds', { 'facebook_ids': friends }, function(cds) { for (i=0; i++; i<cds.length) { $("#cds").append("<div class='cd'>"+cds[i].name+"</div>"); } } ); }); } else { // The user has logged out, and the cookie has been cleared ...Read now
Unlock full access