Authentication Error while extracting user information with Facebook Graph API

≡放荡痞女 提交于 2019-12-25 01:28:16

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5207025/authentication-error-while-extracting-user-information-with-facebook-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!