[英]facebook page tab oauth
我有一個頁面選項卡應用程序,我希望它在用戶第一次訪問選項卡時請求權限(使用用戶的電子郵件)。
我認為這應該足夠簡單,但我已經迷失在hundrends q&a,教程,php / js apis,新舊方法/功能/技術中。 我甚至不確定哪種方式適合我的需要。
我的應用程序正在做的事情很簡單:
if (user_has_liked_page())
include ("fan.php");
else
include ("guest.php");
我想要做的是有這個fb“彈出窗口”請求許可 - 最好只為喜歡該頁面的用戶。
我懇請你不要回復facebook docs / api的所有網址,我已經嘗試了很多這些網址。
如果可能的話,我想知道哪種技術適合這種情況。
也歡迎舉例。
提前致謝。
對於JS解決方案,您可以嘗試類似於fan.php文件中的以下內容
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<button id="fb-login">Login & Permissions</button>
<script>
document.getElementById('fb-login').onclick = function() {
var cb = function(response) {
if (response.status === 'connected') {
//user is logged in here and you have email scope already
} else {
alert('Click the "Login and Permissions" button so we can send you emails');
}
};
FB.login(cb, { scope: 'email' });
};
</script>
channel.html的內容應該是
<script src="//connect.facebook.net/en_US/all.js"></script>
我沒有時間測試這個,我從官方文檔中解除了大部分內容。 我知道你說你不想要鏈接。 但您可能會發現此頁面很有用
https://developers.facebook.com/docs/reference/javascript/
還有一個測試控制台,你可以在這里玩javascript api
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.