実装したアプリケーションで奇妙な動作をし、アクセスするとユーザーの情報を取得します。FacebookのURLの外部からアクセスした場合、アプリケーションはJavaScriptのアクセス許可ダイアログを正しくポップアップします。しかし、このアプリケーションをタブアプリケーションとしてFacebookページに挿入すると、アクセス許可要求ダイアログがポップアップしなくなりました。さらに、FB.getLoginStatus()実装に、ユーザーがログインしていない場合にJavaScriptアラートポップアップウィンドウを使用して、Facebookでのユーザーの現在のログインステータスの検出を配置しました。アプリケーションが「外部」から呼び出された場合アラートがトリガーされます。アプリケーションがFacebookページタブにある場合、そうではありません。これは正しい動作ですか?もしそうなら、Facebookタブアプリケーションで許可リクエストを有効にするにはどうすればよいですか?私'
編集1(CBroeコメントに続く):アプリケーションのcontent.phpマークアップ(ページの読み込み時に実行)で次の呼び出しを使用しています:
<!-- Facebook JS SDK initialization -->
<div id="fb-root"></div>
<script>initFacebookJSSDK();</script>
<!-- End of Facebook JS initialization -->
<script>checkAccessPermission();</script>
<?php include_once 'sites/www.mysite.com/custom_code/custom_index.php';?> // I'm doing
custom code under Drupal
JavaScript関数は、次のようにcustom.jsファイルに実装されています。
function initFacebookJSSDK() {
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxxxxx', // Application's ID
channelUrl : 'www.appsite.com/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true // enable OAuth
});
.........
});
.........
}
function getPerms() {
FB.login(function(response) {
if (!response.authResponse) {
//user refused to grant permissions, redirect to the 'index' page
window.location = "/index";
}
}, {scope:"email"}); // I request the permission to get the email address
}
function checkAccessPermission() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
//user has granted permissions to the application
var uid = response.authResponse.userID; // not used
var accessToken = response.authResponse.accessToken; // not used
}
else if (response.status === 'not_authorized')
// user is logged into Facebook but didn't grand permissions to the app
getPerms();
else {
//user has not granted permissions, redirect to the 'index' page
alert('Please connect with your Facebook account');
window.location = "/index";
}
});
}
PHPスクリプト-ファイル'custom_index.php'には、次のスニペットが含まれています。
$config = array();
$config["appId"] = FB_APP_ID;
$config["secret"] = FB_SECRET_ID;
$config["cookie"] = true;
$facebook = new Facebook($config);
// get user UID
$fb_user_id = $facebook->getUser();
// user's first visit, force the permission request window
if ($fb_user_id == 0) {
$location = $facebook->getLoginUrl(array('scope' => 'email'));
..........
}
// user already gave permission, get the profile and process
if ($fb_user_id != 0) {
$access_token = $facebook->getAccessToken();
$user_profile = $facebook->api('/me', array('access_token'=>$access_token));
..........
}
繰り返しになりますが、ユーザーがFacebookの外部のサイトにアクセスすると非常にうまく機能しますが、Facebookタブアプリケーション(Facebook内のフレーム)として実行すると、許可要求のポップアップウィンドウは表示されません。以前の投稿に関して、JavaScriptステートメントは次のとおりです。
alert('Please connect with your Facebook account');
アプリケーションがFacebook内でタブアプリとして実行されている場合を含め、どちらの場合も実行されます(ブラウザーのキャッシュをクリアする必要がありました)。