问题描述
我正在建立一个Facebook的IFrame应用程序。我使用以下JavaScript代码来请求用户登录并允许应用程序的权限,之后他们应该被重定向到iframe应用程序。代码正常工作。但是,我有两个问题。a。一旦应用程序加载到IFrame中,它将重定向到一个页面(),并显示一个大的facebook图标。当我点击此图标,它会重定向到Facebook登录页面。我想要我的应用程序直接重定向到登录页面,而不是显示在facebook之间的图标页面。
b。当用户在Facebook中点击允许按钮以获得请求的权限时,该页面将重定向到我的主站点(),而不是iframe应用程序()几乎没有变化,它的工作原理,没有显示中间的Facebook图标页面,并且它也正确地重定向到iframe应用程序。
我已经发布在工作解决方案下面,以防有人需要它。
var api_key ='xxxxxxxxxxxx';
var channel_path ='./xd_receiver.htm';
var canvas_url =http://apps.facebook.com/myappxxxx/\"//确保您的canvasurl有一个'/'到底!
函数Initialize(){
FB_RequireFeatures([Api],function(){
FB.Facebook.init(api_key,channel_path);
FB。 ensureInit(function(){
FB.Connect.ifUserConnected(
function(){
var uid = FB.Connect.get_loggedInUser();
if(!uid){
authRedirect();
return;
}
},
authRedirect);
});
});
}
函数authRedirect(){
//这是重定向到Facebook
//http://www.facebook.com/connect/uiserver的示例URL结构。 PHP的?
// app_id = XXXXXXXXXXXXX&
// next = xxxxxxxxxx_success_url_here_XXXXXXX&
// display = page&
// perms = XXXXXX_comma_seperated_permissions_list_hereXXXXXX&
// fbconnect = 1&
//method=permissions.request
window.top.location.href =http://www.facebook.com/connect/uiserver.php?app_id=+ encodeURIComponent( api_key)+& next =+ encodeURIComponent(canvas_url)+& display = page& perms = publish_stream& fbconnect = 1& method = permissions.request;
}
Initialize();
I am building an Facebook IFrame App. I am using the below javascript code to request user to login and allow permissions for the application, after which they are supposed to be redirected to the iframe app. The code works correctly. But, I have two issues with it.
a. as soon as the app loads in IFrame, it redirects to a page (http://www.facebook.com/connect/uiserver.php?app_id=......) and displays a large facebook icon. When I click this icon it redirects to facebook login page. I want my app to redirect to the login page directly instead of showing the inbetween facebook icon page.
b. When the user clicks 'Allow' button for the requested permission in facebook, the page redirects to my main site (http://www.mysite.com) instead of the iframe application(http://apps.facebook.com/myapp).
I have pasted my javascript below, this works with above quirks.
var api_key = 'xxxxxxxxxxxxxxx';
var channel_path = 'xd_receiver.htm';
FB_RequireFeatures(["Api"], function () {
FB.Facebook.init(api_key, channel_path);
var api = FB.Facebook.apiClient;
// require user to login
api.requireLogin(function (exception) {
FB.Connect.showPermissionDialog("publish_stream");
});
});
Help much appreciated.
Thanks for your answers.I used the solution posted by McKAMEY(Facebook API: FB.Connect.requireSession issues) with few changes, and it works as intended, without showing the intermediate facebook icon page, and also it redirects after authentication to the iframe app correctly.
I have posted below the working solution in case someone needs it.
var api_key = 'xxxxxxxxxxxx';
var channel_path = './xd_receiver.htm';
var canvas_url = "http://apps.facebook.com/myappxxxx/"// ensure your canvasurl has a '/' at the end!
function Initialize() {
FB_RequireFeatures(["Api"], function () {
FB.Facebook.init(api_key, channel_path);
FB.ensureInit(function () {
FB.Connect.ifUserConnected(
function () {
var uid = FB.Connect.get_loggedInUser();
if (!uid) {
authRedirect();
return;
}
},
authRedirect);
});
});
}
function authRedirect() {
//This is the Sample URL Structure for redirecting to facebook
//http://www.facebook.com/connect/uiserver.php?
//app_id=XXXXXXXXXXXXX&
//next=xxxxxxxxxx_success_url_here_XXXXXXX&
//display=page&
//perms=XXXXXX_comma_seperated_permissions_list_hereXXXXXX&
//fbconnect=1&
//method=permissions.request
window.top.location.href = "http://www.facebook.com/connect/uiserver.php?app_id=" + encodeURIComponent(api_key) + "&next=" + encodeURIComponent(canvas_url) + "&display=page&perms=publish_stream&fbconnect=1&method=permissions.request";
}
Initialize();
这篇关于Facebook登录和iframe重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!