简体   繁体   English

从auth对话框登录后重定向到Facebook应用程序

[英]Redirect to facebook app after login from auth dialog

I got some problem with my testing app 我的测试应用程序遇到了一些问题

$params = array(
  'scope' => 'read_stream, publish_stream'
);

$loginUrl = $facebook->getLoginUrl($params);
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";

This is the code I use to send user who has not logged in yet to login via facebook auth dialog. 这是我用来发送尚未登录的用户通过facebook auth对话框登录的代码。 The problem is after login using facebook auth dialog user will be redirected to my site which is not in facebook app. 问题是登录后使用facebook auth对话框用户将被重定向到我的网站,这不是在Facebook应用程序。

How can I send user back to facebook app after login using auth dialog ? 如何使用auth对话框登录后将用户发回Facebook应用程序?

Please help 请帮忙

You can use the redirect_uri parameter of getLoginUrl() to tell facebook where you want to send the user after authorization ends (let it be success or failure). 您可以使用getLoginUrl()redirect_uri参数告知facebook在授权结束后要将用户发送到哪里(让它成功或失败)。

There's a number of restrictions on what you can use there, basically you got three options: 你可以在那里使用的东西有很多限制,基本上你有三个选择:

  1. URL under your application's domain. 应用程序域下的URL。
  2. The canvas path of the application (if it has one): https://apps.facebook.com/YOUR_APP_NAMESPACE 应用程序的画布路径(如果有): https://apps.facebook.com/YOUR_APP_NAMESPACEhttps://apps.facebook.com/YOUR_APP_NAMESPACE
  3. Any page url that has your application installed: https://www.facebook.com/PAGE_USERNAME/app_YOUR_APP_ID 安装了您的应用程序的任何页面网址: https://www.facebook.com/PAGE_USERNAME/app_YOUR_APP_IDhttps://www.facebook.com/PAGE_USERNAME/app_YOUR_APP_ID

By default, the php sdk takes the current url as redirect_uri . 默认情况下,php sdk将当前url作为redirect_uri The documentation about these are under the oauth dialog's documentation of the same parameter. 有关这些的文档oauth对话框的相同参数文档下。

Was google-ing about the same issue and found a solution,so thought might as well answer her. 谷歌正在讨论同样的问题,并找到了解决方案,所以想到也可以回答她。

simply add the following code in the main page. 只需在主页面中添加以下代码即可。

$config['appBaseUrl'] = "http://apps.facebook.com/your_app_name/";

if(isset($_GET['code']))
{
     header("location:" . $config['appBaseUrl']);
     exit;
}

$config is the array that i pass while creating the facebook object. $ config是我在创建facebook对象时传递的数组。 In this context,its not necessary to create an array though. 在这种情况下,它不需要创建数组。

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

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