ios facebook sdk 4.0登录错误代码304 [英] ios facebook sdk 4.0 login error code 304
问题描述
我刚刚更新了facebook sdk v4.0
I've just updated facebook sdk v4.0
并根据使用自定义登录UI
-(IBAction)facebookLoginClick:(id)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
} else if (result.isCancelled) {
// Handle cancellations
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if ([result.grantedPermissions containsObject:@"email"]) {
// Do work
}
}
}];
}
但结果总是为零,错误代码为304, am我错过了什么?
BUT the result is always nil and error code is 304, am I missing something?
推荐答案
我遇到了类似的问题。
初始化 FBSDKLoginManager
后,我添加了一行来清除数据和(Facebook)令牌:
After initialising FBSDKLoginManager
I added a line to flush out the data and the (Facebook)Token:
FBSDKLoginManager *loginmanager= [[FBSDKLoginManager alloc]init];
[loginmanager logOut];
希望这会有所帮助。
因此,就像OP要求的那样,我错过了什么吗?
Thus, exactly as the OP asks, "am I missing something"?
是的,以下标准示例代码随处可见,完全错了:
Yes, the following standard example code which is seen everywhere, is simply wrong:
-(IBAction)facebookLoginClick:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
---- ONE MAGIC LINE OF CODE IS MISSING HERE ----
[login logInWithReadPermissions:@[@"email"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error) {...}
else if (result.isCancelled) {...}
else { // (NB for multiple permissions, check every one)
if ([result.grantedPermissions containsObject:@"email"])
{ NSLog(@"%@",result.token); }
}
}];
}
你必须这样做:
-(IBAction)facebookLoginClick:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut]; //ESSENTIAL LINE OF CODE
[login logInWithReadPermissions:@[@"email"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error) {...}
else if (result.isCancelled) {...}
else { // (NB for multiple permissions, check every one)
if ([result.grantedPermissions containsObject:@"email"])
{ NSLog(@"%@",result.token); }
}
}];
}
否则,非常简单,应用程序将无效如果用户碰巧在设备上更改FB帐户。 (除非他们因某些原因重新安装应用程序!)
Otherwise, very simply, the app will not work if the user happens to change FB accounts on the device. (Unless they happen to for some reason re-install the app!)
再一次 - 上面的流行示例代码根本不起作用(如果用户碰巧更改FB帐户,应用程序将进入无限循环。必须进行 logOut
调用。
Once again - the popular sample code above simply does not work (the app goes in to an endless loop) if a user happens to change FB accounts. The logOut
call must be made.
这篇关于ios facebook sdk 4.0登录错误代码304的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!