gpt4 book ai didi

ios - 如何在 IOS 中登录 Facebook 并在新闻提要中分享?

转载 作者:行者123 更新时间:2023-11-29 11:13:03 24 4
gpt4 key购买 nike

我正在使用此代码在 Facebook 新闻源上分享一个项目:

-(void)recommendOnFacebook:(Item *)currentItem{    
if(!facebook){
facebook = [[Facebook alloc] initWithAppId:@"myappid" andDelegate:self];
}
NSMutableDictionary *params2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%@", currentItem.name], @"name",
[shop name], @"caption",
currentItem.description, @"description",
[NSString stringWithFormat:@""], @"link",
currentItem.imagePath, @"picture",
nil, @"actions",
nil];
[facebook dialog:@"feed"
andParams:params2
andDelegate:self];
}

如果我已登录,我可以成功看到共享提要的对话框。但是如果我没有登录,在此代码块完成后,api 对话框会询问我的凭据。我需要的是,如果用户没有登录,api显示对话框,用户成功登录后,显示另一个对话框继续分享进度。

最佳答案

你需要看看 FBSessionDelegate。这是我分享的代码

- (IBAction) facebookShare:(id)sender {
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

if (![delegate.facebook isSessionValid]) {
[delegate.facebook authorize:[NSArray arrayWithObjects:@"publish_stream", @"offline_access", nil]];
}
else {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"TEXT", score.text], @"name",
@"", @"caption",
@"DESC.", @"description",
@"link", @"link",
@"imagelink", @"picture",
nil];
[delegate.facebook dialog:@"feed"
andParams:params
andDelegate:self];
}

}

#pragma mark - FB Session Delegate

- (void)fbDidLogin {
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
/*NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[delegate.facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[delegate.facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];*/
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"TEXT", score.text], @"name",
@"", @"caption",
@"DESC.", @"description",
@"link", @"link",
@"imagelink", @"picture",
nil];
[delegate.facebook dialog:@"feed"
andParams:params
andDelegate:self];
}

编辑

对于公共(public)咖啡馆的注销,您需要确保您永远不会像在 FB session 委托(delegate)方法 fbDidLogin 中那样在 NSUSerDefaults 中保存访问 token

现在实现 FBDialogDelegate 方法

- (void)dialogDidComplete:(FBDialog *)dialog {
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[delegate.facebook logout:self];
}

关于ios - 如何在 IOS 中登录 Facebook 并在新闻提要中分享?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10651787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com