キャンバス アプリとしても機能する Web アプリを作成するために、Facebook の PHP と JS SDK を一緒に使用しようとしています。現在の設定では、ページを離れたとき、またはしばらくすると、システムがログイン画面に戻ってしまうという問題が発生しています。動的ドメイン マッパーを使用していないことが重要です。ユーザーがアクセスしてアプリを体験する可能性のある URL /dev/、/dev/pool/、/dev/pool/edit/ などがいくつかあります。
いろいろ読んだところ、JS SDK を使用した認証が正しい方法であることがわかりました (間違っている可能性がありますか?)。その後、PHP SDK を使用して他のすべてをソートすると、アクセス トークンが自然に取得されます。
これは私の認証設定に問題があることを知っています。時々リロードするのを目にするので、サブページにいる場合は何もしないログインボタンで立ち往生し、サイトに触れないと数分間、システムが理由もなく再認証を試みます。
私が間違っていることについてのアイデアはありますか? ありがとう!
私のサイトに設定されたJSは次のとおりです。
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'XXXXX',
channelUrl: 'http://www.domain.com/channel.php',
status: true,
cookie: true,
xfbml: true,
oauth: true,
});
FB.Event.subscribe('auth.login', function(response) {
alert('refreshing')
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
FB.Canvas.setSize({ width: 810 });
FB.Canvas.setAutoGrow();
};
(function(d, debug){
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" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ true));
</script>
Facebook オブジェクトを呼び出す PHP フローは次のとおりです。
$fb = new FbDoa();
if ($fb->isAuthed() === false) {
echo $fb->getLoginButton();
}
else {
echo $fb->getProfileInfo();
}
FbDoa オブジェクト ( $fb
)の PHP コンテンツは次のとおりです。
public function __construct() {
require_once(Facebook/facebook.php');
$this->facebook = new Facebook(array(
'appId' => 'XXXXX',
'secret' => 'XXXXXXXXXX',
'cookie' => true,
));
$this->user = $this->facebook->getUser();
if ($this->user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$this->user_profile = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
//echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$this->user = null;
}
}
}
public function isAuthed() {
if ($this->user) {
return true;
}
else {
return false;
}
}
public function getLoginButton() {
$scope = 'email,user_likes,friends_likes,publish_actions,publish_stream,read_friendlists';
return '<fb:login-button size="xlarge" perms="'.$scope.'"></fb:login-button>';
}
public function getProfileInfo() {
return $this->user_profile;
}
更新 1:window.location.reload();
ログイン ボタンを何度も押しても何も起こらないように見えますが、更新すると機能します。アプリの認証は数分以上続くはずです。これは、私の前にいくつかの問題があることを意味します。何か案は?
更新 2: サーバー側のコードに問題がある可能性がありますか? 誰もPHP + JS SDKについて何か知っていますか?