登录Facebook Connect后如何返回iPhone网络应用程序? [英] How do I get back to the iPhone web app after having logged in with Facebook Connect?

查看:197
本文介绍了登录Facebook Connect后如何返回iPhone网络应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用jQuery Mobile构建的移动网站。我经常在iPhone上以全屏/移动网络应用程序模式运行它(我已将网络应用程序添加到我的iPhone主屏幕)。

I have a mobile web site built using jQuery Mobile. I often run it in full screen/mobile web app mode on my iPhone (I have added the web app to my iPhone home screen).

在其中一个页面上,用户需要使用Facebook Connect JavaScript API登录Facebook。如果用户尚未登录,则可通过单击登录按钮来完成。此按钮的事件处理程序如下所示:

On one of the pages, the user is required to log in to Facebook using the Facebook Connect JavaScript API. If the user is not already logged in, this is done by clicking a login button. The event handler for this button looks like this:

("#fbLogin").click(function () {
      FB.login(handleStatusChange(response), 
      { scope: "publish_stream", 
        connect_display: "touch" });
});

在上面的代码中,我插入了一些换行符以提高可读性,但值类似于例。回调函数(handleStatusChange)负责处理来自登录请求的响应。

In the above code I have inserted some line breaks for better readability, but the values are like in the example. The callback function (handleStatusChange) takes care of the response from the login request.

当我点击此按钮时,Facebook登录页面将在我的Web应用程序窗口中打开。如果我还没有接受Facebook应用程序,我也必须给它权限。这一切似乎都很好。但是在我获得权限/登录后,我就会挂在一个完全空白的屏幕上。

When I click this, the Facebook login page is opened in my web app window. If I haven't already accepted the Facebook App, I have to give it permissions as well. All this seems to work fine. But after I have given permissions/logged in I'm left hanging on a totally blank screen.

我还尝试了另一种登录方法,将其放入登录按钮事件处理程序:

I have also tried another approach to logging in, by putting this inside the login button event handler:

window.location = "https://www.facebook.com/login.php
?api_key=MY_API_KEY
&cancel_url=http%3A%2F%2Fwww.mywebsiteurl.com%3A8081
&fbconnect=1
&next=http%3A%2F%2Fwww.mywebsiteurl.com%3A8081
&return_session=1
&session_version=3
&v=1.0
&req_perms=publish_stream
&connect_display=touch";

同样,插入了换行符以提高可读性。使用时,它只是一个长串。

Again, line breaks have been inserted for better readability. When used it's just one long string.

cancel_url next 参数中使用的网址是我在Facebook应用中注册的网址。如果我尝试使用其他网址(例如 http://www.google.com ),我会收到错误,因此这似乎是正确的。如您所见,我在开发服务器(端口8081)上使用了不同的端口。这可能是个问题吗?

The URL used in the cancel_url and next parameters is the one I have registered with the Facebook Application. If I try using a different URL (like http://www.google.com) I get an error so the this seems to be correct. As you can see I use a different port on my development server (port 8081). Could this be a problem?

结果类似于前面的例子。我得到了登录/权限页面,但是在完成所有操作后我都会留下一个空白屏幕。我在在旧的Facebook开发人员论坛上阅读这篇文章后尝试了这个。

The result is similar to the previous example. I get the login/permissions pages but I'm left with a blank screen after everything is done. I tried this after reading this post on the old Facebook Developer forum.

另一方面,如果我在Safari(不是整页iPhone网络应用程序)中运行此程序,则登录效果很好。

If I, on the other hand, try running this in Safari (not as a full page iPhone web app) the login works great.

还有什么我可以尝试的吗?在iPhone上以全屏/网络应用模式运行时,是否有人使用JavaScript API Facebook Connect登录?

Is there anything else I can try? Does anyone have a JavaScript API Facebook Connect login working while running in full screen/web app mode on an iPhone?

提前致谢!

推荐答案

不确定这是否对您有所帮助,但我发现添加iOS Safari链接修复,也允许Facebook登录在我的全屏Web应用程序中工作而无需打开第i页常规Safari:

Not sure if this helps you, but I found that adding the iOS Safari link fix, also allowed Facebook login to work in my fullscreen web app without opening up the page i "regular" Safari:

// Make links work in iOS fullscreen web app
function disableSafariLinks() {
    $("a").click(function (event) {
        event.preventDefault();
        window.location = $(this).attr("href");
    });
}

参见 iPhone Safari Web App在新窗口中打开链接

这篇关于登录Facebook Connect后如何返回iPhone网络应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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