gpt4 book ai didi

iOS Facebook SDK startWithGraphPath :parameters post to just SOME friends programmatically

转载 作者:行者123 更新时间:2023-11-28 20:02:08 24 4
gpt4 key购买 nike

在 Facebook 中,您可以发布内容并仅与一些 friend 分享。如何使用 Facebook SDK 在 iOS 上以编程方式完成此操作?

我的应用程序有一个“紧急按钮”,可以发送:a) 用户在 map 上的位置(图片); b) 紧急文本(消息); c) 该帖子仅与用户在配置中选择的 friend 分享。部分(隐私)。

- (void)sendMessage {
//Just an Example: Send an Emergency Post with: message, picture, just to SOME friends.
//This action may not need the User to actually press a button.

//Privacy parameter obtained from:
//https://developers.facebook.com/docs/graph-api/reference/v2.0/post/

NSMutableDictionary *privacy = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
@"100000278095294,100000278095528", @"allow", //Friends Id separeted with commas.
@"", @"deny",
@"CUSTOM", @"value", //Privacy Custom Value
nil];

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:self.emergencyText forKey:@"message"];
[params setObject:self.locationMap forKey:@"picture"];
[params setObject:privacy forKey:@"privacy"];

[FBRequestConnection startWithGraphPath:@"me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(@"Error");
NSLog(@"Error descriptcion %@",error.description);
}else{
NSLog(@"Success");
}
}];

此代码未运行。我从 Facebook 收到错误消息。如果我评论这一行:

// [params setObject:privacy forKey:@"privacy"];

然后它运行正常,我在 FB 中看到了该帖子,但它是一个公开帖子。

我需要发布:消息、图片,只给一些 friend 。

欢迎使用 startWithGraphPath 或使用任何其他命令的任何解决方案!

最佳答案

您必须将隐私格式化为 JSON 字符串,然后将该 json 字符串分配给参数 NSMutableDictionary。

例如:

NSMutableDictionary *privacy = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
@"100000278095294,100000278095528", @"allow", //Friends Id separeted with commas.
@"", @"deny",
@"CUSTOM", @"value", //Privacy Custom Value
nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:privacy
options:NSJSONWritingPrettyPrinted
error:&error];

NSString *jsonString;

if (! jsonData) {
NSLog(@"Got an error: %@", error2);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"to my friend" forKey:@"message"];
[params setObject:self.locationMap forKey:@"picture"];
[params setObject:jsonString forKey:@"privacy"];

关于iOS Facebook SDK startWithGraphPath :parameters post to just SOME friends programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23530096/

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