Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting user information from Facebook using graph API

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.

like image 591
Vinod Singh Avatar asked May 16 '12 10:05

Vinod Singh


People also ask

How do I get my Facebook Graph API User ID?

The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.

What can you do with Facebook Graph API?

The Facebook Graph API is an HTTP-based API that allows developers to extract data and functionality from the Facebook platform. Applications can use this API to programmatically query data, post in pages and groups, and manage ads, among other tasks. The other Facebook APIs are extensions of the Graph API.


1 Answers

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

}

like image 178
hacker Avatar answered Oct 13 '22 00:10

hacker