How do I get my Facebook application to automatically ask for the required permissions post installation

前端 未结 1 1961
日久生厌
日久生厌 2021-01-07 04:01

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\" b

相关标签:
1条回答
  • 2021-01-07 04:02

    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>
    
    0 讨论(0)
提交回复
热议问题