Facebook iOS Authorise and Post Without Dialog?

后端 未结 1 519
庸人自扰
庸人自扰 2020-12-29 14:30

Im just starting out with the Facebook SDK for iOS and checked out the documentation and other help thoroughly but can\'t be successful.

I have started a new view ba

相关标签:
1条回答
  • 2020-12-29 15:11

    You're missing a key point in your delegate, you have to save the session data yourself

    - (void)fbDidLogin {
        // store the access token and expiration date to the user defaults
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:facebook.accessToken forKey:ACCESS_TOKEN_KEY];
        [defaults setObject:facebook.expirationDate forKey:EXPIRATION_DATE_KEY];
        [defaults synchronize];
    }
    

    And then when you initialize facebook you would do the following

    facebook = [[Facebook alloc] initWithAppId:kAppId];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    facebook.accessToken = [defaults objectForKey:ACCESS_TOKEN_KEY];
    facebook.expirationDate = [defaults objectForKey:EXPIRATION_DATE_KEY];
    

    And finally, if you want to post without a dialog you would do this

    NSString *message = @"Visit my blog http://effectivemobility.blogspot.com/";
    NSArray *obj = [NSArray arrayWithObjects:message, nil];
    NSArray *keys = [NSArray arrayWithObjects:@"message", nil];
    
    // There are many other params you can use, check the API
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjects:obj forKeys:keys];
    
    [facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:nil];
    

    I hope that helps

    0 讨论(0)
提交回复
热议问题