douwu8251 2012-12-19 08:03
浏览 52
已采纳

应用程序授权后Facebook重定向到画布URL而不是画布页面

I got help from this post to figure out how to redirect to Facebook authorization page when someone access canvas page who has not yet authorized the app.

Now, I was expecting that after user authorizes the permissions FB will redirect to the canvas page (https://app.facebook.com/myapp). But it is redirecting to the canvas url (https://myhostingapp.com/game.php?...)

Is this expected or is there any thing we can do to control it. How do I tell the API to redirect to the canvas page after authorization?

Right now I am able to think of using the $_SERVER[HTTP_REFERER] to see if I am coming from authorization page and if yes the redirect the page to the canvas page again. But I am hoping there could be much better way of doing it

Canvas url code:

if (Config::$fbAvailalbe){ //see below how this variable is derived
    echo "fb is available";
    $facebook = new Facebook(array(
      'appId'  => Config::$appId,
      'secret' => Config::$appSecret,
    ));

    $user = $facebook->getUser();

    if ($user) {
        echo "app installed";
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $profile = $facebook->api('/me');
      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
    }

    if (!$user) {
      echo " app not installed gonna redirect"; 
      $scope = "scope=email,read_stream,read_friendlists,publish_stream";
      $redirect = $facebook->getLoginUrl(
                    array(
                        'canvas' => 1,
                        'fbconnect' => 0,
                        'req_perms' => $scope
                        )
                    );
      echo '<script>top.location="' . $redirect . '";</script>';
      exit();
      //header("Location: $redirect".$scope);
    } 

    if ($profile){
        $firstName = $profile['first_name'];
        $sid = $profile['id'];
        var_dump($profile);
    }else{
        echo "unable to get profile";
    }

}else{

    echo "fb unavailable, using dmmy";
    $firstName = "Dummy Name";
    $sid = Config::$testsid;

}

Snipet from Config.php

    //this is to derive the $fbAvailable variable
    //we get this condition satisfied when we run the page runs from fb canvas 
    if (isset($_SERVER['HTTP_REFERER'])){

        if (substr_count($_SERVER['HTTP_REFERER'],'apps.facebook.com')){
            self::$fbAvailalbe = 1;
        }
    }
  • 写回答

1条回答 默认 最新

  • duanlaiyin2356 2012-12-19 09:16
    关注

    check documentation here.

    Two errors in the code

    Error#1:

    $scope = "scope = email,read_stream,read_friendlists,publish_stream";
    

    Error#2:

    As per the documentation here (as on now)

    req_params is 'scope'

    Not sure about the 'canvas' and 'fbconnect' parameters which might be potentially ignored as they are not supported any more

    $redirect = $facebook->getLoginUrl(
                        array(
                            'scope' => $scope,
                            'redirect_uri' => 'https://app.facebook.com/myapp'
                            )
                        );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器