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");
}

到目前为止,一切都很顺利。通过用户墙上的对话框发布提要可以正常工作。当我尝试使用以下方式获取用户的名称等信息时,会出现问题:

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

原因和解决方法是什么?

4

1 回答 1

3

我已在以下 wiki 如何使用 Facebook iOS SDK 检索 Facebook 响应中添加了我的整个代码

希望这会对您有所帮助,这是一个有效的代码,如果您有任何问题,请告诉我。

于 2011-03-07T15:10:16.080 回答