FaceBook API,登录应用程序 [英] FaceBook API, login in-app

查看:141
本文介绍了FaceBook API,登录应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循本指南,并已成功创建我的应用程序Facebook整合。

I followed this guide and I've created my app successfully with Facebook integration.

有什么问题?

当用户必须做登录,应用程序退出浏览器(或在Facebook应用程序中,如果已安装)

When the user has to do the login, the app quits in the browser (or in Facebook app, if is installed)

如何将认证完全置于应用程序内?

How do I keep authentication entirely in-app?

推荐答案

oAuth登录的要点是它不会在您的应用程序中发生。它使用快速应用程序切换在受信任的环境(Safari或Facebook应用程序)中执行身份验证。

The point of the oAuth login is that it doesn't happen within your application. It uses fast-app switching to perform the authentication in a trusted environment (either Safari or the Facebook application).

但是,您可以修改Facebook.m在应用程序中进行身份验证,但是用户的凭据将不会被记住。您可以看到,如果您的iOS设备不支持多任务,则会出现一个备份登录对话框。

However, you can modify Facebook.m to do the authentication within your application, but you user's credentials will not be remembered. You can see that if your iOS device doesn't support multi-tasking, there is a backup login dialog.

摘自Facebook.m(第160行):

Excerpt from Facebook.m (around line 160):

if ([device respondsToSelector:@selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {
    if (tryFBAppAuth) {
      NSString *scheme = kFBAppAuthURLScheme;
      if (_localAppId) {
        scheme = [scheme stringByAppendingString:@"2"];
      }
      NSString *urlPrefix = [NSString stringWithFormat:@"%@://%@", scheme, kFBAppAuthURLPath];
      NSString *fbAppUrl = [FBRequest serializeURL:urlPrefix params:params];
      didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
    }

    if (trySafariAuth && !didOpenOtherApp) {
      NSString *nextUrl = [self getOwnBaseUrl];
      [params setValue:nextUrl forKey:@"redirect_uri"];

      NSString *fbAppUrl = [FBRequest serializeURL:loginDialogURL params:params];
      didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
    }
}

// If single sign-on failed, open an inline login dialog. This will require the user to
// enter his or her credentials
if (!didOpenOtherApp) {
    [_loginDialog release];
    _loginDialog = [[FBLoginDialog alloc] initWithURL:loginDialogURL
                                      loginParams:params
                                         delegate:self];
    [_loginDialog show];
}

如果删除第一个条件,它包含代码并将didOpenOtherApp设置为NO,你可以得到你正在寻找的行为。

If you remove the first conditional and it's containing code and set didOpenOtherApp to NO, you can get the behavior you are looking for.

这篇关于FaceBook API,登录应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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