6

I want to get basic user information from Facebook, but having some problem in the following code

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

In the firstMatch I am getting NULL that's why [_delegate accessTokenFound:accessToken]; this methods not get called.

Can anyone please help me out so that I would be able to user information from Facebook

Thanks in advance.

ShawnDaGeek
  • 4,145
  • 1
  • 22
  • 39
Vinod Singh
  • 1,374
  • 14
  • 25
  • Are you using the facebook sdk? Why would you want to get the access token that way instead of using the official Graph API? – vinzenzweber May 17 '12 at 14:34
  • You would usually only need to do as suggested in the Facebook dev manuals: https://developers.facebook.com/docs/mobile/ios/build/#graph – vinzenzweber May 17 '12 at 14:47

1 Answers1

3

Call the fbdid login method after initialising it with app id and 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;
}   

}

hacker
  • 8,919
  • 12
  • 62
  • 108