简体   繁体   English

facebook redirect_uri重定向到本地域,而不是停留在facebook上

[英]facebook redirect_uri redirecting to local domain instead of staying on facebook

My facebook application will not stay on facebook after the request permissions dialog has been shown. 显示请求权限对话框后,我的Facebook应用程序将不会停留在Facebook上。 It keeps redirecting to the redirect_uri (State the obvious), but my question is how can i get the application to run in facebook iframe? 它一直重定向到redirect_uri(显而易见),但是我的问题是我如何让该应用程序在facebook iframe中运行?

I have tried setting the redirect_uri to https://apps.facebook.com/myApp but that is not allowed it shows an error? 我尝试将redirect_uri设置为https://apps.facebook.com/myApp,但这不允许它显示错误?

Given URL is not permitted by the application configuration.: One or more of the given URLs is not allowed by the App's settings. 应用程序配置不允许使用给定的URL 。:应用程序的设置不允许使用一个或多个给定的URL。 It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains. 它必须与网站URL或Canvas URL匹配,或者域必须是该应用程序域之一的子域。

My current Code 我当前的代码

<?php
require 'facebook/facebook.php';

// Get User ID
$facebook_config = array(
  'appId'  => '8**************3',
  'secret' => '5*************************d',
  'cookie'  =>  true
);

$facebook = new Facebook($facebook_config);

$user = $facebook->getUser();

$login_url = $facebook->getLoginUrl(array(
  'redirect_uri' => 'localhost';
  'scope'   =>  'user_location'
));

$logout_url = $facebook->getLogoutUrl();

if($user)
{
    $user_profile = $facebook->api('/me');
    header("Content-Type:text/plain");
    print_R($user_profile);
    die();
}
else if(!$user)
{
    echo "<script type='text/javascript'>top.location.href = '$login_url';</script>";
}
?>

You can remove this line: 'redirect_uri' => 'localhost'; 您可以删除以下行: 'redirect_uri' => 'localhost';

Since, after login if nothing is mentioned in redirect_uri , it will redirect to the same page automatically. 因为,登录后,如果redirect_uri未提及任何内容,它将自动重定向到同一页面。

In case you want to proceed to some other page, say success.php , you should give the redirect_uri wrt the canvas url ie the actual url of this page, not http://apps.facebook ....... 如果您想转到其他页面,例如success.php ,则应给redirect_uri wrt画布URL,即该页面的实际URL,而不是http://apps.facebook .......

Thank you for your answer but when 'redirect_uri' => 'localhost'; 谢谢您的回答,但是当'redirect_uri' => 'localhost'; is removed it still redirects to localhost and gets stuck. 被删除后,它仍然重定向到localhost并被卡住。

I did a quick fix that did a redirection back to facebook 我做了一个快速修复,将其重定向回了Facebook

$token = $_GET['code'];
if ($token) { ?>
<form action="https://apps.facebook.com/MyApp/" method="post" name='frm'>
    <input type="hidden" name="token" value="<?=$token?>">
</form>
<script language="JavaScript">
    document.frm.submit();
</script>

That redirected everything back to facebook and would work, but as you said here 这会将所有内容重定向回Facebook,并且可以正常工作,但是正如您在此处所说

In case you want to proceed to some other page, say success.php, you should give the redirect_uri wrt the canvas url ie the actual url of this page, not http://apps.facebook ....... 如果您想转到其他页面,例如success.php,则应给redirect_uri wrt画布URL,即该页面的实际URL,而不是http://apps.facebook .......

i changed my redirect_uri from localhost to https://apps.facebook.com/MyApp/index.php and everything worked smoothly, 我将我的redirect_uri从localhost更改为https://apps.facebook.com/MyApp/index.php ,一切顺利进行,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM