我正在使用Facebook PHP SDK(2.1.2)。我想要做的就是幾乎每個Facebook應用都有req_perms
。愚蠢的「請求權限」框會在您安裝時彈出。我不想要一個用戶不得不推動的按鈕。我不想彈出窗口。我不想使用FBML,since they're doing away with it。我如何讓我的Facebook應用程序在安裝後自動請求所需的權限
這是標準的Facebook權限對話框,顯示我的應用程序應該顯示在畫布iframe中的位置。
我想:(!不是我想要的)
<?php if(!$me): ?>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; <?php echo $loginUrl; ?>">
</head>
<?php die(); ?>
<?php endif; ?>
也就是說,由於某種原因,顯示鏈接到我想要的正確的URL Facebook的標誌
<?php if($me): ?>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $appid; ?>',
session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<fb:redirect url="<?php echo $loginUrl; ?>" />
<?php die("</html>"); ?>
這一個顯示一個空白頁。
<?php if($me): ?>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $appid; ?>',
session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Whenever the user logs in, we refresh the page.
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<script>
FB.login(function(response) {
if (response.session) {
if (response.perms.indexOf('publish_stream') != -1) {
//User has logged in and given us publish_stream permissions
);
else {
//User has logged in but not given us publish_stream
}
}
else {
//User is not logged in
}, {perms:'offline_access,publish_stream'});
</script>
此人還顯示一個空白頁。
我想要的並不是不受歡迎,但Facebook文檔是我遇到過的最糟糕的文檔。什麼都沒有這種愚蠢簡單的事情不應該花兩天的時間才能搞清楚。
這是我結束了與解決方案:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $appid; ?>',
session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.session) {
// Logged in and connected user, someone you know.
} else {
// No user session available, redirect them to login.
window.top.location = "<?php echo $loginUrl; ?>";
}
});
// Whenever the user logs in, we refresh the page.
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
我得到firebugs控制檯這個JavaScript錯誤: 無效標籤 http://mywesite.com/facebook/plaque/?fb_sig_in_iframe=1&fb_sig_base_domain=mywebsite.com&fb_sig_locale=en_US&fb_sig_in_new_facebook=1&fb_sig_time=1287603452.3819&fb_sig_added=0&fb_sig_country=us&fb_sig_api_key = cdb7efae5da476f5da16f911d4dd47ee&fb_sig_app_id = 138890676153908&fb_sig = c70e97233c693f13d9e18be66ab8517d Line 209 – user446699 2010-10-20 19:38:36
真棒,我得到它的工作最後的代碼現在在我的問題 – user446699 2010-10-20 19:57:25