如何通过画布中的重定向来授权Facebook应用程序? [英] How to authorize Facebook app using redirect in canvas?
问题描述
使用javascript api,我正在尝试开发Facebook应用程序,但我无法在画布中的重定向方案中获得授权。我在一个弹出的方案中很容易地工作:
$(#loginButton)点击(function(e){
FB.login(function(response){
if(response.perms){
perms();
}
},{perms:'publish_stream'} );
但弹出窗口应该是一个不必要的额外点击,因为我看到的每个其他应用程序请求授权以前甚至显示你的着陆页,如下所示:
我认为他们只是使用重定向方案,所以我花了整个一天尝试不同的方法可以找到:
标题(位置:https://graph.facebook.com/oauth/ autho rize?client_id =。 $ gAppId。 & redirect_uri =。 urlencode($ gUrl)。 &安培;烫发= publish_stream);
header(Location:http://www.facebook.com/login.php?v=1.0&api_key=$ gApiKey。& next =。urlencode($ gUrl )& canvas =);
header(Location:http://www.facebook.com/connect/uiserver.php?app_id=。$ gAppId。& next =。urlencode($ gUrl)。 &安培; return_session = 0&安培; fbconnect = 0&安培;帆布= 1&安培; legacy_return = 1&安培;方法= permissions.request);
但是,所有这些,而不是显示授权请求的东西,显示一个这样的链接: p Q Q Q Q .png
令人激动的是,如果我在新标签页中打开iframe的地址,我就会得到我想要的授权请求。但是我希望它立即显示,没有额外的点击,像其他所有的应用程序。
这是一个正在进行授权和请求权限的应用程序的一个例子以重定向形式显示目标网页:
www.facebook.com/send.fortune.cookies
他们是如何做的?
我知道这是几个月前...但是这是你应该添加权限检查到您的画布。
if($ session){
try {
$ uid = $ facebook-> getUser();
$ me = $ facebook-> api('/ me');
$ accesstoken = $ session ['access_token'];
} catch(FacebookApiException $ e){
error_log($ e);
}
}
if($ me)
{
//做你必须做的
} else {
$ loginUrl = $ facebook-> getLoginUrl(
array(
'canvas'=> 1,
'fbconnect'=> 0,
'req_perms'=> ;'publish_stream'
)
);
echo'< script> top.location ='。$ loginUrl。';< / script>';
// echo'< fb:redirect url ='。$ loginUrl。'/>';
// header('Location:'。$ loginUrl);
}
I'm trying to get into making Facebook apps but I'm having trouble getting authorization working in a redirect scheme inside the canvas.
Using the javascript api, I got it working pretty easily in a popup scheme:
$("#loginButton").click(function(e) {
FB.login(function(response) {
if (response.perms) {
perms();
}
}, {perms : 'publish_stream'});
But the popup should be an unnecessary extra click, because every other application I see requests the authorization before even showing you the landing page. Like this:
I figure they're simply using a redirect scheme. So I spent the entire day trying the different ways I could find:
header("Location: https://graph.facebook.com/oauth/authorize?client_id=" . $gAppId . "&redirect_uri=" . urlencode($gUrl) . "&perms=publish_stream");
header("Location: http://www.facebook.com/login.php?v=1.0&api_key=" . $gApiKey . "&next=" . urlencode($gUrl) . "&canvas=");
header("Location: http://www.facebook.com/connect/uiserver.php?app_id=" . $gAppId . "&next=" . urlencode($gUrl) . "&return_session=0&fbconnect=0&canvas=1&legacy_return=1&method=permissions.request");
But all of them, instead of showing the authorization request stuff, show a link like this:
Hilariously, if I open the iframe's address in a new tab, I get the authorization request like I wanted. But I want it to display immediately, without an extra click, like every other app.
Here's an example of an app that is doing authorization and requesting permissions all in one go, in redirect form, before even displaying the landing page:
www.facebook.com/send.fortune.cookies
How are they doing it?
I know that this is months old now... but this is what you should do to add permission checking to your canvas.
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$accesstoken=$session['access_token'];
} catch (FacebookApiException $e) {
error_log($e);
}
}
if($me)
{
// do what you have to do
}else {
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'publish_stream'
)
);
echo '<script>top.location="'.$loginUrl.'";</script>';
//echo '<fb:redirect url="' . $loginUrl . '" />';
//header('Location: '.$loginUrl);
}
这篇关于如何通过画布中的重定向来授权Facebook应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!