开发者

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]) {
   [fac开发者_StackOverflowebook 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.


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.


You need to implement Facebook's Single-Sign-On feature.

http://developers.facebook.com/docs/guides/mobile/#ios

This link has the step-by-step guide for implementing SSO, if you follow it carefully your App will request for permission once, then it will never request permission again (until the user remove your App)

Note that, you will need to go to www.facebook.com and use the "Developer Tools" to create a new Facebook App, you will be the admin of the app, and you will have your AppID, you will need this too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜