使用Facebook Graph API提取用户信息时出现身份验证错误 [英] Authentication Error while extracting user information with Facebook Graph API

查看:153
本文介绍了使用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.

这篇关于使用Facebook Graph API提取用户信息时出现身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆