Iphone 使用graph API从Facebook获取用户信息
我想从Facebook获得基本的用户信息,但在下面的代码中有一些问题Iphone 使用graph API从Facebook获取用户信息,iphone,facebook,facebook-graph-api,fbconnect,facebook-ios-sdk,Iphone,Facebook,Facebook Graph Api,Fbconnect,Facebook Ios Sdk,我想从Facebook获得基本的用户信息,但在下面的代码中有一些问题 -(void)checkForAccessToken:(NSString *)urlString { NSError *error; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"access_token=(.*)&" options:0 error:&error]; if
-(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];
}**
}
}
在第一个匹配中,我得到了NULL,这就是为什么[_delegateaccesstokenfound:accessToken];无法调用此方法
有人能帮我吗?这样我就可以从Facebook上获取用户信息了
提前感谢。在使用应用程序id和凭据初始化fbdid登录方法后,调用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;
}
}您正在使用facebook sdk吗?为什么您希望通过这种方式获得访问令牌,而不是使用官方的Graph API?您通常只需要按照Facebook开发手册中的建议进行操作: