重定向回页面标签用户进行身份验证后? [英] Redirect back to page tab after user authenticates?

查看:155
本文介绍了重定向回页面标签用户进行身份验证后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何去重定向用户返回到我的网页后,他们验证我的应用程序标签?我不能把一个特定的URL在重定向,因为我的应用程序将生活在多个页面。所以,不知何故,我需要获取页面的id,放入的URL。我试图使用会话变量,但它似乎并没有对我的工作。 :(这里是我的code的一部分...

How should I go about redirecting the user back to my page's tab after they authenticate my app? I cannot put one specific url in for the redirect since my app will live on multiple pages. So somehow I need to grab the page's id and put it into the url. I've tried to use session variables but it doesn't seem to be working for me. :( Here's a portion of my code...

$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
}

正如你可以看到我正在尝试设置一个会话变量来获取页面的ID ..但是,这不是为我工作:(可变回波出来就好了,当我访问我的网页...但我猜它在验证过程中取得了一些进展丢失。

As you can see I'm trying to set a session variable to grab the page's id.. but that's not working for me :( The variable echo's out just fine when I visit my page.. but I'm guessing its getting lost somewhere during the authentication.

推荐答案

所以,当一个页面添加/安装你的应用程序,你应该存储页面的链接与页面一起 ID

So when a Page add/install your app, you should store the page's link along with the page's id.

现在,当加载你的页面标签,Facebook将发参数,将包含页 ID (与其他信息一起,请参阅文档)。您检索编号,从数据库获取页面的链接,构建你的页面的选项卡链接,这将是像(其中 $页是页面的数据库记录):

Now when your page tab is loaded, Facebook will send the page parameter which will contain the page id (along with other info, refer to the documentation). You retrieve that id, get the page's link from your db and construct your page tab link, which would be something like (where $page is the page's db record):

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

由于您使用的是PHP-SDK,你这是怎么构建你的登录:

Since you are using the PHP-SDK, this is how you construct your login:

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

当然,你可能不希望直接重定向到登录,而是要操作链接的电话:

Of course you may not want to redirect to the login directly but instead have a call to action link:

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

这篇关于重定向回页面标签用户进行身份验证后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆