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

时间:2011-03-05 21:53:20

标签: ios facebook facebook-graph-api facebook-ios-sdk

我试图通过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");
}

到目前为止,一切都很顺利。在用户的墙上发布通过对话框工作正常。当我尝试使用以下命令获取用户信息时出现问题:

[facebook requestWithGraphPath:@"me" andDelegate:self];

但是fbDidLogin和requestDidLoad都没有被调用。对于requestDidLoad,我在请求didLoad之前检查了didLoadRawResponse:

- (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."}}

原因和解决方案是什么?

1 个答案:

答案 0 :(得分:3)

我在以下维基中添加了我的整个代码 How to retrieve Facebook response using Facebook iOS SDK

希望这对您有所帮助,如果您有任何疑问,请提供相关信息。