Getting user information from Facebook using graph API
Asked Answered
R

1

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.

Raising answered 16/5, 2012 at 10:12 Comment(2)
Are you using the facebook sdk? Why would you want to get the access token that way instead of using the official Graph API?Maximo
You would usually only need to do as suggested in the Facebook dev manuals: developers.facebook.com/docs/mobile/ios/build/#graphMaximo
T
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;
}   

}

Transoceanic answered 29/5, 2012 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.