gpt4 book ai didi

facebook - 用户身份验证后重定向回页面选项卡?

转载 作者:行者123 更新时间:2023-12-02 21:55:02 25 4
gpt4 key购买 nike

在用户验证我的应用程序后,我应该如何将用户重定向回我的页面选项卡?我无法输入一个特定的网址进行重定向,因为我的应用程序将驻留在多个页面上。所以我需要以某种方式获取页面的 id 并将其放入 url 中。我尝试过使用 session 变量,但它似乎对我不起作用。 :( 这是我的代码的一部分...

$signed_request = $facebook->getSignedRequest();

$_SESSION['TrueID'] = $signed_request['page']['id'];

$fbconfig['appBaseUrl'] = "http://www.facebook.com/pages/".$_SESSION['TrueID']."/".$_SESSION['TrueID']."?sk=app_241321439259320";

/*
* If user first time authenticated the application facebook
* redirects user to baseUrl, so I checked if any code passed
* then redirect him to the application url
* -mahmud
*/
if (isset($_GET['code'])){
header("Location: " . $fbconfig['appBaseUrl']);
exit;
}
//~~

//
if (isset($_GET['request_ids'])){
//user comes from invitation
//track them if you need
}

正如你所看到的,我正在尝试设置一个 session 变量来获取页面的 id.. 但这对我不起作用:( 当我访问我的页面时,变量 echo 很好.. 但我猜它是在身份验证过程中迷路了。

最佳答案

因此,当主页添加/安装您的应用时,您应该存储页面的链接以及页面的id

现在,当您的页面选项卡加载时,Facebook 将发送包含页面 idpage 参数(以及其他信息,请参阅 documentation ) 。您检索该 ID,从数据库获取页面的链接并构建页面选项卡链接,这将类似于(其中 $page 是页面的数据库记录):

$redirect_uri = $page['page_link'] . '?sk=app_' . $APP_ID

由于您使用的是 PHP-SDK,因此您可以这样构建登录:

$user = $facebook->getUser();
if(!$user) {
$url = $facebook->getLoginUrl(array('redirect_uri' => $redirect_uri, 'scope' => 'read_stream'));
echo "<script>top.location.href = '$url';</script>";
exit;
}

当然,您可能不想直接重定向到登录,而是使用号召性用语链接:

<a href="<?php echo $url;?>" target="_top">Connect</a>

关于facebook - 用户身份验证后重定向回页面选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8158657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com