简体   繁体   English

facebook PHP SDK redirect_uri到页面选项卡

[英]facebook PHP SDK redirect_uri to page tab

im using the PHP SDK to get user to authorize my app. 即时通讯使用PHP SDK来使用户授权我的应用程序。 the thing that is a bit tricky is that i;m doing this inside a tab. 有点棘手的是,我在选项卡中执行此操作。 the redirect uri will break the tab 'iframe' and just open as a normal app,i do not want this. 重定向uri将打破“ iframe”标签,只是作为普通应用打开,我不希望这样做。 how can i keep it inside the page tab iframe. 我如何将其保留在页面标签iframe中。 below is my code; 下面是我的代码;

<?php

include("utility.php");
include("db_setup.php");
require_once "base_facebook.php";
require("facebook.php");
$facebook = new Facebook(array(
    'appId'  => 'xxxxxx',
    'secret' => 'xxxxxx',
));

$conn = connectUserDB();
$user = $facebook->getUser();
if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.

          //$user_profile = $facebook->api('/me?fields=name,id,email');

header( 'Location: submitted.php' ) ;

       } catch (FacebookApiException $e) {
    //print_r($e);
        $user = null;
    }
}
// $user is null : $user is either not logged in or the token is not valid
else if(!$user) { 
$params = array(
'scope' => 'email',
'redirect_uri' => 'submitted.php'
);

$loginUrl = $facebook ->getLoginUrl($params);

echo '<script type="text/javascript">';
echo 'top.location.href = " '.$loginUrl.' " ; ';
echo '</script>';
}

?>

If you need to log in user without having him/her leave your tab, you could use javascript SDK (you can call function FB.login() which will open popup). 如果您需要在不离开用户的情况下登录用户,则可以使用javascript SDK (您可以调用函数FB.login()来打开弹出窗口)。

If you want to keep using php, on your "normal app" (the page that gets opened in iframe on Facebook) you can simply make a redirect back to your tab on Facebook. 如果您想继续使用php,请在“常规应用”(在Facebook iframe中打开的页面)上,直接重定向回Facebook上的标签页。 So that after user gets logged in and redirected to your page, you redirect him back to Facebook tab. 这样,在用户登录并重定向到您的页面后,您可以将其重定向回Facebook选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM