0

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?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
WaJiyaz
  • 512
  • 1
  • 8
  • 25
  • if fbDidLogin is not getting called, can you please check if this is getting called fbDidNotLogin, and I am hoping you have the right value for "fbAppId" – Yogesh Mar 06 '11 at 01:43
  • @Yogesh: No, even fbDidNotLogin isn't getting called. I guess it is because new SDK transfers control to Facebook application or Safari temporarily, whichever is available. It detects if user is logged in already or otherwise asks for logging in. I have checked both cases. And yes, fbAppId is also correct. As I said I can post on wall. The only problem left is authorizing while extracting user information. – WaJiyaz Mar 06 '11 at 10:26
  • interesting so when you can post to wall there is not authorizing issue but when you trying to extract user information. Sorry man I cannot help unless I look up the whole code. One more suggestion is probably you can delete the app in your simulator and try to authenticate again and see if that solves the problem – Yogesh Mar 07 '11 at 02:36
  • @Yogesh: Yes I did refresh simulator, no useful result :). I've uploaded more code. This is all I did. Everything is mostly in viewDidLoad because most other methods are not being called. I haven't used regular LoginDialog and logging in and out because I want to try automatic login of latest Graph API. But I think getting access_token is still important. When you worked with it, did you manually created logging in and out? And did you acquired access_token by requesting URL? What is the better approach to go with Graph API? – WaJiyaz Mar 07 '11 at 10:27

1 Answers1

3

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.

Community
  • 1
  • 1
Yogesh
  • 1,333
  • 3
  • 16
  • 35
  • Thanks a lot Yogesh. Of course it helped. What else can be clearer than the whole code. So, summarizing, it can't be done with new Single Sign-On feature. Must implement manual login to get access. Thanks again :) – WaJiyaz Mar 08 '11 at 14:25