开发者

Facebook iOS Authorise and Post Without Dialog?

开发者 https://www.devze.com 2023-03-08 20:29 出处:网络
Im just starting out with the Facebook SDK for iOS and checked out the documentation and other help thoroughly but can\'t be successful.

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 based app and authorised just as recommended in the docs. Everytime I start the app its switches to the Facebook ap开发者_运维问答p (which I have installed on my iPhone) and says already authorised, press okay. How can I stop it repeatedly doing this?

I also have tried posting to Facebook without a dialog. The console tells me a request is made but then a error occurs (doesn't crash but the didFailWithError tells me).

Anyway I haven't posted any of my code as it seems relatively simple so if there is someone who knows how to do this I would massively appreciate any help, and possibly even a code sample.

Thanks.


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

精彩评论

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

关注公众号