【问题标题】:iPhone facebook sdk shows Valid session even when I logged out through Facebook app即使我通过 Facebook 应用程序注销,iPhone facebook sdk 仍显示有效会话
【发布时间】:2012-03-21 11:42:00
【问题描述】:

经过数小时的代码尝试和在线搜索,我不得不寻求帮助。我在 UITableViewCell 中有一个共享按钮。在其触摸操作中,我打开 facebook 登录对话框,然后如果登录,我会显示提要对话框。它工作正常,但即使我通过 Facebook 应用程序注销 sessionIsValid 显示是。这是代码...

if(indexPath.row==0)
        {
            AppId=@"xxx";

            AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
            appDelegate.scheduleViewController=self;
            self.facebook = [[Facebook alloc] initWithAppId:AppId andDelegate:self];
            // [self.facebook requestWithGraphPath:@"me" andDelegate:self];
            if ([defaults objectForKey:@"FBAccessTokenKey"] 
                && [defaults objectForKey:@"FBExpirationDateKey"]) {
                self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
                self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];

            }
            if (![self.facebook isSessionValid]) {
                [self.facebook authorize:permissions];
            }
            else
                [self doStuffAfterLogin:[self.facebook accessToken]]; 

        }

- (void)fbDidLogin {     
    [defaults setObject:[self.facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[self.facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    [self doStuffAfterLogin:[self.facebook accessToken]];
}
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {

    NSLog(@"%@", [error localizedDescription]);
    NSLog(@"Err details: %@", [error description]);
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"Error!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alertView show];
    [defaults removeObjectForKey:@"FBAccessTokenKey"];
    [defaults removeObjectForKey:@"FBExpirationDateKey"];
    [self.facebook authorize:permissions]; 

}

-(void)doStuffAfterLogin:(NSString*)accessToken;
{
    NSMutableString *imgUrl=[[NSMutableString alloc]init];
    if([[defaults objectForKey:@"imageUrl"] isEqualToString:@""])
        imgUrl= @"http://artist.eventseekr.com/images/no-photo.png";
    else
        imgUrl=[defaults objectForKey:@"imageUrl"];
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   AppId, @"app_id",
                                   imgUrl, @"picture",
                                   [NSString stringWithFormat:@"Watch %@ in action at the %@ event",[defaults objectForKey:@"name"],[defaults objectForKey:@"eventName"]], @"caption",
                                   @"Sample Festival App", @"description",
                                   nil]; 

     [self.facebook dialog:@"feed" andParams:params andDelegate:self];

}

【问题讨论】:

    标签: iphone facebook session fbconnect


    【解决方案1】:

    没错。每个应用程序都有自己的沙盒区域。因此,您已授权您的应用程序,并且您的应用程序已存储一个可用于验证自身的令牌。它对任何其他应用程序一无所知。因此,如果您在 facebook 应用程序中注销,它不知道。

    【讨论】:

    • 所以我所做的是在应用程序启动时删除 NSUserdefaults 中的 accessToken 和过期值,我想不出任何其他解决方案。有什么想法吗?
    猜你喜欢
    • 2011-11-14
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 2014-09-05
    • 1970-01-01
    相关资源
    最近更新 更多