使用 Facebook Graph API 提取用户信息时出现身份验证错误
我正在尝试通过FBConnect最新的SDK提取用户的基本信息。我的代码很简单:
- (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");
}
到目前为止,一切显然都很顺利。在用户墙上发布一个 feed through 对话框效果很好。当我尝试获取用户的信息(例如名称)时,会出现问题:
[facebook requestWithGraphPath:@"me" andDelegate:self];
但 fbDidLogin 和 requestDidLoad 都没有被调用。对于requestDidLoad,我检查了didLoadRawResponse,因为它在请求didLoad之前调用:
- (void)request:(FBRequest *)request didLoadRawResponse:(NSData*)data {
NSString *response = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Response is = %@",response);
[response release];
}
我得到的响应是以下身份验证错误:
{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}
原因和解决方案是什么?
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];
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已在以下 wiki 中添加了我的整个代码
如何使用 Facebook iOS SDK 检索 Facebook 响应< /a>
希望这会对您有所帮助,这是一个有效的代码,如果您有任何问题,请告诉我。
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.