使用 Facebook Graph API 提取用户信息时出现身份验证错误

发布于 2024-10-20 05:44:46 字数 2061 浏览 2 评论 0原文

我正在尝试通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2024-10-27 05:44:46

我已在以下 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文