6

Tôi muốn nhận được thông tin người dùng cơ bản từ Facebook, nhưng có một số vấn đề trong đoạn mã sauBắt thông tin người dùng từ Facebook sử dụng graph API

-(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];    
     }** 
    } 
} 

Trong firstMatch Tôi nhận được NULL đó là lý do tại sao [_delegate accessTokenFound: accessToken ]; phương pháp này không được gọi.

Bất kỳ ai cũng có thể giúp tôi để tôi có thể thông tin người dùng từ Facebook

Xin cảm ơn trước.

+0

Bạn có sử dụng sdk facebook? Tại sao bạn muốn nhận mã thông báo truy cập theo cách đó thay vì sử dụng API đồ thị chính thức? – vinzenzweber

+0

Bạn thường chỉ cần làm như được đề xuất trong hướng dẫn sử dụng Facebook dev: https://developers.facebook.com/docs/mobile/ios/build/#graph – vinzenzweber

Trả lời

3

Gọi phương pháp đăng nhập fbdid sau initialising nó với id ứng dụng và credentials.-

(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; 
} 

}

Các vấn đề liên quan