如何让我的Facebook应用程序自动要求安装后所需的权限 [英] How do I get my Facebook application to automatically ask for the required permissions post installation

查看:83
本文介绍了如何让我的Facebook应用程序自动要求安装后所需的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Facebook PHP SDK(2.1.2)。所有我想要做的是几乎每个具有 req_perms 的Facebook应用程序。在安装它时,会弹出愚蠢的权限请求框。



我不想要用户必须推送的按钮。我不想弹出一个弹出窗口。我不想使用FBML,因为他们正在消除它



这是标准的Facebook权限对话框,显示我的应用程序应该在画布中显示iframe。



我试过: p>

 <?php if(!$ me):?> 
< head>
< meta HTTP-EQUIV =REFRESHcontent =0;<?php echo $ loginUrl;?>>
< / head>
<?php die(); ?>
<?php endif; ?>

由于某种原因,显示了一个Facebook徽标链接到我想要的正确URL(不是我想要的!

 <?php if($ me):?> 
window.fbAsyncInit = function(){
FB.init({
appId:'<?php echo $ appid;?>',
session: php echo isset($ session)?'.json_encode($ session)。'':'null';?> //当PHP已经有
时,不要重新获取会话状态:true ,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true //解析XFBML
});

//每当用户登录时,我们刷新页面
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';?> //当PHP已经有
时,不要重新获取会话状态:true ,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true //解析XFBML
});

//每当用户登录时,我们刷新页面。
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){
//用户已登录并给予我们publish_stream权限
);
else {
//用户已登录但未提供给我们publish_stream
}
}
else {
//用户未登录
},{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';?> //当PHP已经有
时,不要重新获取会话状态:true ,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true //解析XFBML
});

FB.getLoginStatus(function(response){
if(response.session){
//登录和连接的用户,你认识的人
} else {
//没有用户会话可用,重定向到登录
window.top.location =<?php echo $ loginUrl;?>;
}
});

//每当用户登录时,我们刷新页面。
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>


解决方案

基本上,您使用PHP SDK获取登录URL,然后对该URL执行JavaScript重定向。示例 http://github.com/facebook/php-sdk/blob/master/examples/example.php 除了重定向之外,还为您做了一切。在该示例中,它们具有您单击以登录的链接。如果你希望它是自动的,请执行以下操作。

 < script> 
FB.getLoginStatus(function(response){
if(response.session){
//登录和连接的用户,你认识的人
}
else {
//没有用户会话可用,重定向到登录
window.top.location =<?php echo $ loginUrl;?&$
}
});
< / script>


I'm using the Facebook PHP SDK (2.1.2). All I want to do is what almost every Facebook application with req_perms has. The stupid "request for permissions" box to pop up when you install it.

I do not want a button that the user has to push. I do not want a popup to appear. I do not want to use FBML, since they're doing away with it.

This is the standard Facebook permissions dialog that shows up where my application should show up in the canvas iframe.

I tried:

<?php if(!$me): ?>
    <head>
        <meta HTTP-EQUIV="REFRESH" content="0; <?php echo $loginUrl; ?>">
    </head>
<?php die(); ?>
<?php endif; ?>

That, for some reason, showed a Facebook logo linked to the correct URL I wanted (not what I want!)

<?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>"); ?>

This one showed a blank page.

<?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>

This one also shows a blank page.

What I want isn't unpopular, but the Facebook documentation is the worst documentation I've ever come accross. Nothing works. Something this idiotically simple should not take two days to figure out.

Here's the solution I ended up with:

<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>

解决方案

Basically, you use the PHP SDK to get the login URL and then do a JavaScript redirect to that URL. The example http://github.com/facebook/php-sdk/blob/master/examples/example.php does everything for you except for the redirect. In the example, they have a link you click to login. If you want it to be automatic, do the following.

<script>
    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; ?>
        }
    });
</script>

这篇关于如何让我的Facebook应用程序自动要求安装后所需的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆