3

私のアプリケーションは Facebook 認証を使用します。

FB.init({

    appId: config.fbAppId,
    status: true,
    cookie: true,
//  xfbml: true,
//  channelURL : 'http://WWW.MYDOMAIN.COM/channel.html', // TODO
    oauth  : true

});

// later...

FB.login(function(response)
{
    console.log(response);
    console.log("authId: " + response.authResponse.userID);
    gameSwf.setLoginFacebook(response.authResponse.accessToken);
}, {scope:'email,publish_actions,read_friendlists'});

そしてそれを使用すると、人々は自分のウォールに投稿できます:

var obj = {
      method: 'feed',
      link: linkUrl,
      picture: pictureUrl,
      name: title,
      caption: "",
      description: message
    };

    function callback(response) {
      // console.log("Post on wall: " + response);
    }

    FB.ui(obj, callback);

これは問題なく動作しますが、1 つだけ問題があります。人々の場合:

  1. アプリにログインします。
  2. フェイスブックからログアウトします。
  3. アプリからウォール ポストを作成してみます。

ウォール ポスト ダイアログを開くことができません。コンソールには、「X-Frame-Options によって表示が禁止されているため、ドキュメントの表示を拒否しました。」と表示されます。

代わりに、Facebook にログイン プロンプトをユーザーに表示させることはできますか? または、エラーを検出して、Facebook にログインしていないことをユーザーに伝えることはできますか?

4

2 に答える 2

2

あなたが試して使用できるのは FB.getLoginStatus で、ユーザーが接続されている場合、これによりユーザーはウォール投稿を完了することができます。接続されていない場合は、ウォールに投稿する前に FB.login メソッドを呼び出します。

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;
    } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook, 
        // but has not authenticated your app
    } else {
        // the user isn't logged in to Facebook.
    }
});

http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

ログインとログアウトのイベントもあり、これらの応答を監視して何かを行うことができます。

FB.Event.subscribe('auth.login', function(response) {
    // do something with response
});

FB.Event.subscribe('auth.logout', function(response) {
    // do something with response
});

http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

于 2012-02-28T13:57:24.697 に答える