简体   繁体   English

Facebook iOS 授权和发布没有对话?

[英]Facebook iOS Authorise and Post Without Dialog?

Im just starting out with the Facebook SDK for iOS and checked out the documentation and other help thoroughly but can't be successful.我刚开始使用 iOS 的 Facebook SDK 并彻底检查了文档和其他帮助,但无法成功。

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 app (which I have installed on my iPhone) and says already authorised, press okay.每次我启动应用程序时,它都会切换到 Facebook 应用程序(我已经安装在我的 iPhone 上)并说已经授权,按 OK。 How can I stop it repeatedly doing this?我怎样才能阻止它反复这样做?

I also have tried posting to Facebook without a dialog.我也尝试过在没有对话框的情况下发布到 Facebook。 The console tells me a request is made but then a error occurs (doesn't crash but the didFailWithError tells me).控制台告诉我发出了一个请求,但随后发生错误(不会崩溃,但 didFailWithError 告诉我)。

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您在委托中遗漏了一个关键点,您必须自己保存 session 数据

- (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 = [[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我希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM