Facebook Iframe 应用程序身份验证?
我开发了一个 Facebook 应用程序,该应用程序在 Facebook 画布的 iframe 内运行。为了使其正常工作,我向用户请求扩展权限。如果用户尚未授权该应用程序,我将使用 PHP SDK 中的 getLoginUrl() 方法将他/她发送到登录页面。
它有效,但并不漂亮。该方法将用户发送到身份验证页面之前的登陆页面。它看起来像这样:
当我单击“转到 Facebook.com”时,我会看到权限请求的实际页面(如果我打印网址,复制它并将其输入到新的浏览器窗口中,我也可以直接进入权限页面)。当我从 Iframe 进行重定向时,如何让 Facebook 跳过此步骤?
我的代码如下所示(使用 CodeIgniter 和 Facebook PHP SDK):
$this->facebook = new Facebook(array(
'appId' => '{MY_APP_ID}',
'secret' => '{MY_SECRET}',
'cookie' => TRUE,
'domain' => $_SERVER['SERVER_NAME']
));
$this->facebook->getSession();
try {
$this->me = $this->facebook->api('/me');
}
catch (FacebookApiException $e) {
$this->me = NULL;
}
if ( is_null($this->me) ) {
redirect($this->facebook->getLoginUrl(array(
'req_perms' => 'offline_access,read_stream,publish_stream,user_photos,user_videos,read_friendlists',
'next' => $this->config->item('base_url').'fblogin.php?redirect_uri='.$this->uri->uri_string()
)));
}
I have developed a Facebook application that runs inside an iframe in the Facebook canvas. For it to work properly I request extended permissions from the user. If the user hasn't authorized the application I send him/her to a login page with the getLoginUrl() method in the PHP SDK.
It works, but it's not pretty. The method sends the user to a landing page before the authentication page. It looks like this:
When I click "Go to Facebook.com" I see the actual page for permission requests (I also get right to the permissions page if I print the url, copy it and enter it into a new browser window). How do I make Facebook skip this step when I do the redirect from an Iframe?
My code looks like this (using CodeIgniter and Facebook PHP SDK):
$this->facebook = new Facebook(array(
'appId' => '{MY_APP_ID}',
'secret' => '{MY_SECRET}',
'cookie' => TRUE,
'domain' => $_SERVER['SERVER_NAME']
));
$this->facebook->getSession();
try {
$this->me = $this->facebook->api('/me');
}
catch (FacebookApiException $e) {
$this->me = NULL;
}
if ( is_null($this->me) ) {
redirect($this->facebook->getLoginUrl(array(
'req_perms' => 'offline_access,read_stream,publish_stream,user_photos,user_videos,read_friendlists',
'next' => $this->config->item('base_url').'fblogin.php?redirect_uri='.$this->uri->uri_string()
)));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要重定向父框架(即 _top)而不是 iFrame 本身?
I think you need to redirect the parent frame (i.e. _top) rather than the iFrame itself?
我这样做的方法是使用以下内容设置 INDEX.PHP 文件
将你的画布网址指向 http://yoursite.com/INDEX.php
中的回调网址INDEX.PHP 中的上述代码设置了授予权限后在何处查看。
FBMain.php 看起来像这样
它更清楚一点。我花了一段时间才弄清楚,但我到达那里,认为我能提供帮助。
The way I do it is set up an INDEX.PHP file with the following
Then point your canvas url to http://yoursite.com/INDEX.php
The callback url in the above code which will be in INDEX.PHP sets where to look after permissions are granted.
FBMain.php looks like this
Hope its a little clearer. It took me a while to figure it out, but I got there, thought I would help.