使用Facebook Graph API提取用户信息时出现身份验证错误
我正在尝试通过FBConnect最新的SDK提取用户的基本信息.我的代码很简单:
I am trying to extract user's basic information through FBConnect latest SDK. My code is simple:
- (void)viewDidLoad {
[super viewDidLoad];
facebook = [[Facebook alloc] initWithAppId:fbAppId];
NSArray* permissions = [[NSArray arrayWithObjects:@"user_about_me",@"read_stream",nil]retain];
[facebook authorize:permissions delegate:self];
[facebook requestWithGraphPath:@"me" andDelegate:self];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
fbAppId, @"app_id",
[NSString stringWithFormat: @"Some Text"], @"description",
@"My Test App", @"name",
@"Test Facebook Graph API",@"message",
nil];
[facebook dialog:@"feed" andParams:params andDelegate:self];
}
- (BOOL) application: (UIApplication*) application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
- (void) fbDidLogin {
NSLog(@"FB didLogin");
}
- (void) fbDidNotLogin:(BOOL)cancelled {
NSLog(@"FB didNotLogin");
}
- (void) request:(FBRequest *)request didLoad:(id)result {
NSLog(@"request-didLoad-result");
}
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {
NSLog(@"received response");
}
到目前为止,一切似乎都进展顺利.通过用户墙上的对话框发布供稿效果很好.当我尝试通过以下方式获取用户信息(例如姓名)时,会发生问题:
Up till this point everything goes well apparently. Publish a feed through dialog on user's wall works fine. The problem occurs when I try to get user's information like name with:
[facebook requestWithGraphPath:@"me" andDelegate:self];
但是fbDidLogin和requestDidLoad都没有被调用.对于requestDidLoad,我检查了didLoadRawResponse,因为它在请求didLoad之前被调用:
But neither fbDidLogin nor requestDidLoad is called. For requestDidLoad, I checked didLoadRawResponse as it is called before request didLoad:
- (void)request:(FBRequest *)request didLoadRawResponse:(NSData*)data {
NSString *response = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Response is = %@",response);
[response release];
}
我得到的是以下身份验证错误:
What I get in response is the following authentication error:
{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}
原因和解决方法是什么?
What is the reason and the solution?
我已在以下Wiki中添加了全部代码 如何使用Facebook iOS SDK检索Facebook响应
I have added my whole code in the following wiki How to retrieve Facebook response using Facebook iOS SDK
希望这会对您有所帮助,如果您有任何疑问,请使用此代码.
Hope this will help you, this is a working code if you have any question please let me know.