[英]iOS Facebook SDK startWithGraphPath:parameters post to just SOME friends programmatically
In Facebook, you can post something and share it with just some friends. 在Facebook中,您可以发布一些东西,并只与一些朋友分享。 How can this be done programmatically on iOS using Facebook SDK?
如何使用Facebook SDK在iOS上以编程方式完成此操作?
My App has an "Emergency Button" that sends: a) User Location on a Map (picture); 我的应用程序具有一个“紧急按钮”,用于发送:a)地图上的用户位置(图片); b) An emergency text (message);
b)紧急文本(消息); and c) The post is only shared with the friends the user has chosen in the config.
c)帖子仅与用户在配置中选择的朋友共享。 section (privacy).
部分(隐私)。
- (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");
}
}];
} }
This code in not running. 此代码未运行。 I get an error from Facebook.
我从Facebook得到一个错误。 If I comment this line:
如果我对此行发表评论:
// [params setObject:privacy forKey:@"privacy"];
Then it runs fine and I see the post in FB, but it is a public post. 然后运行正常,我在FB中看到了该帖子,但这是公开帖子。
I need to post: message, picture, just to some friends. 我需要发布:消息,图片,仅发给一些朋友。
Any solution using startWithGraphPath
or using any other command is welcome! 欢迎使用
startWithGraphPath
或任何其他命令的任何解决方案!
You must format the privacy as a JSON string and then assign that json string to the params NSMutableDictionary. 您必须将隐私格式设置为JSON字符串,然后将该JSON字符串分配给参数NSMutableDictionary。
For Example: 例如:
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"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.