Search code examples
iphoneobjective-cfacebookpermissionsfbdialogs

why fbdidlogin didn't call?


- (id)init {
if (self == [super init]) {
    facebook = [[Facebook alloc] initWithAppId:kAppId];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    if (![facebook isSessionValid]) {
        permissions =  [[NSArray arrayWithObjects:
                         @"read_stream", @"user_birthday", 
                         @"publish_stream", nil] retain];
        [facebook authorize:permissions delegate:self];
    }

    [self login];
}
return self;

}

- (void)login {
if (![_session isConnected]) {
    [self postToWall];  
}


if (![facebook isSessionValid]) {
   [facebook authorize:permissions delegate:self];
}
}

- (void)fbdidLogin {
[[NSUserDefaults standardUserDefaults] setObject:self.facebook.accessToken forKey:@"FBAccessToken"];
[[NSUserDefaults standardUserDefaults] setObject:self.facebook.expirationDate forKey:@"FBExpirationDate"];

// User has logged in to Facebook, now get their userId from Facebook
[facebook requestWithGraphPath:@"me" andDelegate:self];
}

-(void)postToWall
{
SBJSON *jsonWriter = [[SBJSON new] autorelease];

NSDictionary *actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       @"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil];

NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary *attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"Your Happiness!", @"name",
                            @"asda", @"caption",
                            @"asdf", @"description",
                            nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Share on Facebook",  @"user_message_prompt",
                               actionLinksStr, @"action_links",
                               attachmentStr, @"attachment",
                               nil];


[facebook dialog:@"stream.publish" andParams:params andDelegate:self];

}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

return [facebook handleOpenURL:url]; 
}

This is my methods for calling facebook dialog boxes.But every time when i click to score for publishing;The permission box came first.I need to give permission after that the publish dialog box comes.I want to give permission ones and i want it to save it;after saving it i don't wanna see the permission box ever again.How can i do it?What is wrong with my code?

edit: My access token and expiration date is null i guess thats because of this.


Solution

  • A few things to check, you call the method login handling method "fbdidLogin" instead of fbDidLogin. This is case sensitive.

    Make sure in your view controller header file that you added FBSessionDelegate as one of the protocols you support. That could be a reason fbDidLogin is not called. You could always add an NSLog to verify that the fbDidLogin method is reached.