Facebook iOS Authorize and Post without dialogue?

I am just starting out with the Facebook SDK for iOS and have carefully checked the documentation and other help, but cannot succeed.

I started a new view-based application and enabled it as recommended in the docs. Each time I launch the application, its switches to the Facebook application (which I installed on my iPhone) and say that it is already allowed, click "OK." How can I stop this several times?

I also tried posting to Facebook without dialogue. The console tells me that the request is made, but then an error occurs (not a failure, but didFailWithError tells me).

In any case, I didn’t post any of my codes, because it seems relatively simple, so if there is someone who knows how to do this, I would greatly appreciate any help and, possibly, even a code sample.

Thanks.

+6
source share
1 answer

You do not have a key moment in your deletion, you yourself must save the session data

- (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 will 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 dialogue, you will do it

 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 this helps

+9
source

Source: https://habr.com/ru/post/889149/