How to authorize Facebook app using redirect in canvas?

前端 未结 4 1612
猫巷女王i
猫巷女王i 2020-12-08 12:30

I\'m trying to get into making Facebook apps but I\'m having trouble getting authorization working in a redirect scheme inside the canvas.

Using the javascript api,

相关标签:
4条回答
  • 2020-12-08 13:02

    Using FB Javascript SDK, it can be done something like --

    FB.getLoginStatus(function(response) {
          if (response.status === 'connected') {
             loggedIn(response);
          } else {
            top.location = encodeURI("https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_APP_URI&response_type=token");
          }
    
    0 讨论(0)
  • 2020-12-08 13:04

    The problem is that server side redirection is only redirecting your inner app frame instead of redirecting the whole page, and Facebook doesn't like displaying their system dialogs inside frames.

    You would need some client side redirection, probably something along those lines:

    <script>
        <?php 
            if($doRedirect) {
                echo 'top.location="http://redirect_url";';
            }
        ?>
    </script>
    
    0 讨论(0)
  • 2020-12-08 13:05

    Maybe this helps :

        if(!$facebook->api_client->users_isAppUser())
    {
        ?>
        <fb:redirect url="http://www.facebook.com/login.php?v=1.0&api_key=111111111111&next=http%3A%2F%2Fapps.facebook.com%2Fapp_name%2F&canvas=&req_perms=publish_stream"/>
        <?php
    }
    
    0 讨论(0)
  • 2020-12-08 13:09

    I know that this is months old now... but this is what you should do to add permission checking to your canvas.

    if ($session) {
      try {
        $uid = $facebook->getUser();
        $me = $facebook->api('/me');
        $accesstoken=$session['access_token'];
      } catch (FacebookApiException $e) {
        error_log($e);
      }
    } 
    
    if($me)
    {
       // do what you have to do
    }else {
        $loginUrl = $facebook->getLoginUrl(
            array(
                'canvas' => 1,
                'fbconnect' => 0,
                'req_perms' => 'publish_stream'
            )
        );
        echo '<script>top.location="'.$loginUrl.'";</script>';
        //echo '<fb:redirect url="' . $loginUrl . '" />';
       //header('Location: '.$loginUrl);
    }
    
    0 讨论(0)
提交回复
热议问题