1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<html>
  <body>
    <h1> My Registration page </h1>
<div id="fb-root"></div>
<script>
  //run as soon as the sdk is loaded in the browser
  window.fbAsyncInit = function() {
    console.log("The FB SDK has been loaded");

    FB.init({
      appId      : '246147952143368', // App ID
      channelUrl : '//192.168.112.128/homefolder/wikidb/interface/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
    setup();


  FB.Event.subscribe('auth.login', function () { setup(); });

  };
  function setup(){
    // test the logged in status of user here
    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        console.log("The user is logged in and authenticated to app.");
        // the user is logged in and has authenticated your
        // app, and response.authResponse supplies
        // the user's ID, a valid access token, a signed
        // request, and the time the access token 
        // and signed request each expire
 //       document.getElementById("login-button").innerHTML="";
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        greet();
        getFriends();
        } else if (response.status === 'not_authorized') {

        console.log("The user is logged in to Facebook, but has not authenticated your app ");

        } else {

        console.log("The user isn't logged in to Facebook.");
      }
    });
  }

  function greet() {
    FB.api('/me', function (response) {
      console.log('Welcome, ' + response.name + "!");
      console.log('Your email id is : '+ response.email);
    }
    );
  }

  function getFriends() {
    FB.api('/me/friends', function(response) {
      if(response.data) {
        for(friend in response.data)
        {
          console.log(response.data[friend].name + ' has id:' + response.data[friend].id);
        }
        } else {
        alert("Error!");
      }
    });
  }
  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
        <fb:login-button perms="email" autologoutlink="true"></fb:login-button>
  </body>
</html>