6

我想从 Facebook 获取基本用户信息,但在以下代码中遇到了一些问题

-(void)checkForAccessToken:(NSString *)urlString {
    NSError *error;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"access_token=(.*)&" options:0 error:&error];
    if (regex != nil) {
        **NSTextCheckingResult *firstMatch = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, [urlString length])];
        if (firstMatch) {
            NSRange accessTokenRange = [firstMatch rangeAtIndex:1];
            NSString *accessToken = [urlString substringWithRange:accessTokenRange];
            accessToken = [accessToken stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [_delegate accessTokenFound:accessToken];               
        }**
    }
}

在 firstMatch 我得到 NULL 这就是为什么 [_delegate accessTokenFound:accessToken]; 这个方法不会被调用。

谁能帮助我,以便我能够从 Facebook 获取用户信息

提前致谢。

4

1 回答 1

3

使用应用程序 ID 和凭据初始化后调用 fbdid 登录方法。-

(void)fbDidLogin {

NSLog(@"fbDidLogin");
isFacebookLoaded=YES;


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSLog(@"i am in and my acees token is %@ %@ and call me.CALLshowAloadingView",[facebook accessToken],[facebook expirationDate]) ;
[self.facebook requestWithGraphPath:@"me" andDelegate:self];
if ( [delegate respondsToSelector:@selector(showAloadingView)] ) 
{
    NSLog(@" CALLshowAloadingView");
    // calling delegate method. For this method to function, the delegate should be implemented in the calling class.
    [delegate showAloadingView];                
}


// Inform the delegate that Login is successful
if ( [delegate respondsToSelector:@selector(loginStatus:)] ) {
    // calling delegate method. For this method to function, the delegate should be implemented in the calling class.
    [delegate loginStatus:YES];                 
    return;
}   

}

于 2012-05-29T09:43:46.260 回答