سؤال

I'd like to obtain an access token to access the Graph API from my Canvas app using the Javascript SDK. Here is my code:

FB.init({
    appId: conf.FACEBOOK_APP_ID,
    xfbml: true,
    channelUrl:
      window.location.protocol + '//' + window.location.host + '/channel.html'
  });
FB.getLoginStatus(function(response) { 
    var accessToken = response.authResponse.accessToken;
    [...] 
  }

However, this assumes the user is logged in when visiting the app. Facebook's Javascript SDK documentation suggests testing

if (response.status === 'connected')

before obtaining the access token. It's unclear whether this is meant only for external sites which ask their users to login to Facebook, or whether it applies to Canvas apps as well. My impression is that Canvas apps can only be accessed from inside Facebook, and so they require the user to be logged in to access them. I have two related questions:

1. Is checking response.status necessary? Can a user ever access a Canvas app without being logged in?

2. Does a Facebook canvas app need a login button?

هل كانت مفيدة؟

المحلول

  1. Is checking response.status necessary? Can a user ever access a Canvas app without being logged in?

Of course they can.

  1. Does a Facebook canvas app need a login button?

If you want the user to connect to your app, then yes of course.

For handling login within a canvas app, I’d recommend using FB.login.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top