gpt4 book ai didi

ios - 在 Facebook 上发布状态

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

我正在实现一个用户可以在其中发布状态的应用程序。如果用户默认登录他/她的设备,则以下代码将起作用

  if(!self.accountStore)
self.accountStore = [[ACAccountStore alloc] init];
if(NSClassFromString(@"SLComposeViewController") != nil)
{
ACAccountType *facebookTypeAccount = [self.accountStore
accountTypeWithAccountTypeIdentifier:@"com.apple.facebook"];
NSLog(@"facebookTypeAccount..:%@",facebookTypeAccount);
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookTypeAccount];
if (facebookTypeAccount) {
if ([accounts respondsToSelector:@selector(count)]) {
[self.accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:@{ACFacebookAppIdKey: @"214267482030378", ACFacebookPermissionsKey: @[@"email"]}
completion:^(BOOL granted, NSError *error) {
if(granted){
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookTypeAccount];
_facebookAccount = [[accounts lastObject]retain];
}
else
{
NSLog(@"Failed, Error: %@", error);
}
}];
}
else
{
[self openSession];
}
}
}

否则控制会转到这个方法

- (void)openSession{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_stream",@"email",
nil];
[FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceEveryone
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
[self sessionStateChanged:session state:state error:error];

}];

但是登录后我需要在 Facebook 上发送状态。如果我尝试使用这种方法

   -(void)poststatus{
[[FBSession activeSession] reauthorizeWithPublishPermissions:@[ @"publish_stream" ]
defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession
*authSession, NSError *authError) {
// If auth was successful, create a status update FBRequest
if (!authError) {
FBRequest *postRequest = [FBRequest requestForPostStatusUpdate:@"Hello, world!"];
[postRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// TODO: Check for success / failure here
}];
}
}];

然后它给出错误 Failed, Error: Error Domain=com.apple.accounts Code=8 "The operation couldn't be completed. (com.apple.accounts error 8.)"如果有人有,请帮助我关于这个概念的一些想法。

提前致谢。

最佳答案

要求:

@[@"publish_stream", @"publish_actions"]

不仅仅是:

@[ @"publish_stream" ]

阅读更多: https://developers.facebook.com/docs/reference/login/extended-permissions/

publish_stream  The publish_stream permission is required to post to a Facebook Page's timeline. For a Facebook User use publish_actions.

您还使用了已弃用的功能。尝试:

[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:];

关于ios - 在 Facebook 上发布状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19243767/

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