0

在 [self.facebook requestWithGraphPath:@"me" andDelegate:self]; 我得到了上面提到的异常。这是我的代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.facebook = [[Facebook alloc] initWithAppId:@"<app id hidden>" andDelegate:self];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    if (![self.facebook isSessionValid]) {

        NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"user_likes", 
                                @"read_mailbox",
                                nil];
        [self.facebook authorize:permissions];

        [self.facebook requestWithGraphPath:@"me" andDelegate:self];

    }




}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

    return [self.facebook handleOpenURL:url]; 
}

- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[self.facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[self.facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];



}
-(void)request:(FBRequest *)request didLoad:(id)result
{
    NSArray *messagesResult= result;
}
-(void) request:(FBRequest *)request didFailWithError:(NSError *)error
{
    NSLog(@"%@",error);
}
4

1 回答 1

1

您应该等待 Facebook 授权您并致电fbDidLogin您的 FB 代表。然后,在fbDidLogin你启动requestWithGraphPath:. 在您的代码中,您在收到令牌之前启动图形请求,因为 FB 授权是异步的。

于 2012-06-07T17:30:57.893 回答