Advertisement
ShawnsSpace

Permissions Flow

Jun 30th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.   window.fbAsyncInit = function() {
  3.   FB.init({
  4.     appId      : '190670741097534', // App ID
  5.     channelUrl : '//www.wtf-teen.com/channel.html', // Channel File
  6.     status     : true, // check login status
  7.     cookie     : true, // enable cookies to allow the server to access the session
  8.     xfbml      : true  // parse XFBML
  9.   });
  10.  
  11.  
  12.   FB.Event.subscribe('auth.authResponseChange', function(response) {
  13.     // Here we specify what we do with the response anytime this event occurs.
  14.     if (response.status === 'connected') {
  15.       testAPI();
  16.       location.reload();
  17.  
  18.     } else if (response.status === 'not_authorized') {
  19.      
  20.       FB.login();
  21.     } else {
  22.    
  23.       FB.login();
  24.      
  25.     }
  26.  }, {scope: 'publish_actions'});
  27. };
  28.  
  29.   // Load the SDK asynchronously
  30.   (function(d){
  31.    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
  32.    if (d.getElementById(id)) {return;}
  33.    js = d.createElement('script'); js.id = id; js.async = true;
  34.    js.src = "//connect.facebook.net/en_US/all.js";
  35.    ref.parentNode.insertBefore(js, ref);
  36.   }(document));
  37.  
  38.   // Here we run a very simple test of the Graph API after login is successful.
  39.   // This testAPI() function is only called in those cases.
  40.   function testAPI() {
  41.     console.log('Welcome!  Fetching your information.... ');
  42.     FB.api('/me', function(response) {
  43.       console.log('Good to see you, ' + response.name + '.');
  44.     });
  45.   }
  46. function addPerm(perm){
  47.  FB.login(function (response) {
  48.  if(response.authResponse){
  49.    // handle the response
  50. if(document.getElementById(''+perm+'add')){
  51. document.getElementById(''+perm+'add').innerHTML = "" + response.status;
  52. }else{
  53. document.getElementById('response_object').innerHTML = "" + response.status;
  54. }
  55. if(response.status==='connected'){
  56. location.reload();
  57. }
  58. }
  59.  },{scope: ''+perm+''});
  60.  
  61. }
  62. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement