Domanda

Per verificare se il puther ha dato tutte le autorizzazioni necessarie, lo faccio così:

    FB.login(function(response){
             console.log(response.status);
            if (response.status == 'connected') {
               /* user gave permssions */
            }else{
                 /* user didnt, unmark the checkbox */
                 $('input:checkbox').removeAttr('checked');
            }
    }, { scope: 'publish_stream' });
.

Il problema è che questo è sempre il restituzione del vero, non importa se l'utente: accessi, importo o chiude il popup.

Qualche idea del perché?

ha anche provato: se (risposta.authresponse) {senza successo ..

È stato utile?

Soluzione

Il problema qui è che publish_stream è un Autorizzazione estesa , che significa L'utente può disattivare quell'autorizzazione. In generale, quando un utente colpisce il blocco del codice nella tua callback, hanno autenticato la tua app, ma non necessariamente con tutte le autorizzazioni che hai chiesto da quando alcuni possono essere Autorizzazioni estese . response.status viene utilizzato solo per comunicare lo stato del fatto che l'utente abbia autenticato l'applicazione, non se hanno accettato o meno tutte le richieste di dialogo / autorizzazioni che hai richiesto. Nel tuo caso, publish_stream è un'autorizzazione estesa in modo da non essere garantito di avere quell'autorizzazione per l'utente nella tua callback. Se stai chiedendo publish_stream come autorizzazione incrementale dopo che un utente è già stato autenticato, il tuo assegno condizionale su response.status restituisce sempre TRUE (dal momento che dalla definizione L'utente ha già autenticato la tua applicazione).

Se si desidera verificare di avere l'autorizzazione publish_stream nel callback, verificare l'autorizzazione utilizzando l'endpoint /me/permissions sull'aPI del grafico.

Cosa vuoi è qualcosa del genere:

FB.login(function(response){
    if (response.status == 'connected') {
        FB.api('/me/permissions', function(response) {
            var permsArray = response.data[0];
            // Permissions that are needed for the app
            var permsNeeded = ['publish_stream'];
            var permsToPrompt = [];
            for (var i in permsNeeded) {
                if (permsArray[permsNeeded[i]] == null) {
                    permsToPrompt.push(permsNeeded[i]);
                }
            }

            if (permsToPrompt.length > 0) {
                $('input:checkbox').removeAttr('checked');
            }
         }
    } else {
        /* user didnt, unmark the checkbox */
        $('input:checkbox').removeAttr('checked');
    }
}, { scope: 'publish_stream' });
.

Altri suggerimenti

Non so perché, ma il seguente codice funziona bene per me almeno ~

window.fbAsyncInit = function() {
  FB.init({
  appId      : '<?php echo FACEBOOK_APP_ID ?>',
  status     : true, 
  cookie     : true,
  xfbml      : true,
  oauth      : true,
  });
 FB.getLoginStatus(function(response){
  if (response.status === 'connected') {
    // 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
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
    var signed_request = response.authResponse.signedRequest;
    // avoid using cookie
    self.location= "<?php echo site_url()?>/signup/fb_login/"+uid;

  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
    FB.login(function(response) {
    if (response.authResponse) {
      self.location="<?php echo site_url()?>/signup/fb_register";
      /* FB.api('/me', function(response) { */
      /*   }); */
    }  }, {scope: 'email,user_hometown'});
  } else { // unknown
    // the user isn't logged in to Facebook.
  }
});
  FB.Event.subscribe('auth.login', function(response) {
      window.location.reload();
    });
    FB.Event.subscribe('auth.logout', function(response) {
      window.location.reload();
    });
 };
(function(d){
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
  js = d.createElement('script'); js.id = id; js.async = true;
  js.src = "//connect.facebook.net/en_US/all.js";
  d.getElementsByTagName('head')[0].appendChild(js);
  }(document));
.

`

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top