Facebook画布应用程式“redirect_uri”在授权后崩溃iframe&认证 [英] Facebook canvas app "redirect_uri" breaks out of iframe after authorization & authentication

查看:109
本文介绍了Facebook画布应用程式“redirect_uri”在授权后崩溃iframe&认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在升级我现有的FB应用程序,并绝对bonkers试图获得一个简单的PHP iframe画布应用程序来授权和验证(以及使用SSL)。从来没有看过这么多的例子...

I'm upgrading my existing FB apps, and going absolutely bonkers trying to get a simple PHP iframe canvas app to authorize and authenticate (as well as use SSL). Never looked through so many examples...

这里是我被困住的地方:用户授权应用程序后,应用程序验证用户(我可以带有令牌OK的图形请求),redirect_uri发生,整个页面刷新,离开Facebook和thenjust显示我的Canvas URL页面(与我的服务器的域)的内容,而不是在Facebook上ifgleed。

Here's where I'm stuck: After the user authorizes the app, and the app authenticates the user (I am able to make a graph request with the token OK), the redirect_uri happens, and the whole page refreshes, leaving Facebook and thenjust shows me the contents of my "Canvas URL" page (with my server's domain), rather than iframed on Facebook.

我目前有一个粗略的两步过程...

I currently have this as a crude two step process...

这是我的代码在第一页(index.php):

Here's what my code looks like on the first page (index.php):

<?php
require('src/facebook.php');

$app_id = '123456789';
$app_secret = '1234secrets1234';
$canvas_page = "https://apps.facebook.com/123456789/";
$canvas_url = "https://myserver.com/apptest/";

$code = $_REQUEST['code'];

if(!$code){
$display= 'page';
$scope= 'manage_pages, offline_access, read_insights, publish_stream, user_about_me, user_likes, email'; 
$redirect_url = 'https://myserver.com/apptest/step2.php';
$oauth_url    = 'https://www.facebook.com/dialog/oauth?canvas=1&client_id='.$app_id.'&display='.$display.'&redirect_uri='.urlencode($redirect_url).'&scope='.$scope;
$config = array('appId'  => $app_id,'secret' => $app_secret,'cookie' => true,'domain' => true);
$facebook_client = new Facebook($config);

echo "<script type=\"text/javascript\">top.location.href = \"".$oauth_url."\";</script>";
}
?>

和第二页(step2.php):

and the second page (step2.php):

<?php
require('src/facebook.php');

$app_id = '123456789';
$app_secret = '1234secrets1234';
$canvas_page = "https://apps.facebook.com/123456789/";
$canvas_url = "https://myserver.com/apptest/";


if($_REQUEST['code']){
$code=$_REQUEST['code'];
$redirect_url = 'https://myserver.com/apptest/step2.php';
$link="https://graph.facebook.com/oauth/access_token?canvas=1&client_id=".$app_id."&redirect_uri=".urlencode($redirect_url)."&client_secret=".$app_secret."&code=".$code;
$string = file_get_contents($link);
$auth_token=substr($string, 13, 150);

$graph_url = "https://graph.facebook.com/me?access_token=".$auth_token;
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
} 

同样,一旦用户授权了应用程序,用户,图调用工作。

Again, once the user has authorized the app, and the app has authenticated the user, the graph call works.

任何想法?

推荐答案

在应用程序>设置>基本我没有设置一个命名空间,所以它给我的应用程序在Facebook上的URL是这样的: https://apps.facebook.com/123456789/ ,现在使用命名空间将它们更改为: https://apps.facebook.com/myappname 。所以这可能是它。我试图仔细按照此页面上的简单PHP自动化演示: https://developers.facebook。 com / docs / appsonfacebook / tutorial / ,现在似乎工作正常。

Well I did get this working. On the app > settings > basic I hadn't set a namespace, so the URL it gave me for the app on facebook was like this: https://apps.facebook.com/123456789/ and now with the namespace they changed it to: https://apps.facebook.com/myappname. So that may have been it. I tried to carefully follow the simple PHP autorization demo on this page: https://developers.facebook.com/docs/appsonfacebook/tutorial/ and it seems to work ok now.

感谢您的帮助!

这篇关于Facebook画布应用程式“redirect_uri”在授权后崩溃iframe&amp;认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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