的Facebook SDK IOS登录问题
我按照指令,从我的应用程序实现登录过程给Facebook:的Facebook SDK IOS登录问题
https://developers.facebook.com/docs/mobile/ios/build/#implementsso
这里是我的代码:
- (IBAction)facebookButton:(id)sender {
facebook = [[Facebook alloc] initWithAppId:@"383032031757454" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"read_stream",
nil];
[facebook authorize:permissions];
permissions=nil;
}
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
登录之后,允许权限到应用程序,Safari保持打开状态,我必须手动返回到我的应用程序,但SDK提供的示例应用程序“Hackbook”在接受Safari中的权限并登录后,会解除Safari并返回到应用程序。我想要做同样的事情,但我没有成功。
这是的.plist文件:
感谢
在应用程序Facebook页面上,您是否配置了iOS SSO的应用程序?
你在使用什么操作系统?你的代码将只适用于4.2 +
你没有完全按照说明,你的plist文件有点不对(我不认为这是问题)。
我使用的是5.0,所以我认为它一定没问题。我之前的plist版本与Facebook表示完全一样,但它也不起作用。谢谢。 – theomen
您可以通过在Facebook.m
内部挖掘一点点来轻松确定为什么它不起作用。在Facebook.m
中检查方法handleOpenURL:
。
// Facebook.m
- (BOOL)handleOpenURL:(NSURL *)url {
// If the URL's structure doesn't match the structure used for Facebook authorization, abort.
if (![[url absoluteString] hasPrefix:[self getOwnBaseUrl]]) {
return NO;
}
NSString *query = [url fragment];
// Version 3.2.3 of the Facebook app encodes the parameters in the query but
// version 3.3 and above encode the parameters in the fragment. To support
// both versions of the Facebook app, we try to parse the query if
// the fragment is missing.
if (!query) {
query = [url query];
}
NSDictionary *params = [self parseURLParams:query];
设置断点下面NSDictionary *params = [self parseURLParams:query];
和读取它的内容。您应该看到错误消息为什么登录不起作用。
嗨,按照说明编译ARC版本的库后,生成的文件夹只包含.h文件,我有点迷失了它到.m文件的位置。谢谢。 – theomen
谢谢!我修改了.plist文件,但Safari返回相同的错误。我已上传.plist文件值。 – theomen
再次尝试删除应用程序并清理构建。 – Ananth
清洁构建和模拟器后出现同样的错误。谢谢。 – theomen