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

标签 ios facebook facebook-graph-api

在 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/

相关文章:

ios - 如何向iOS模拟器发送模拟远程通知?

ios - 尝试在已连接的 iPad 上运行 Xcode 7 Instruments、Allocations/Leaks 工具时收到错误 'Unable to attach to task; port invalid'

android - Facebook API 异常 "This link could not be posted."

ios - Facebook-由app_scoped_user_id打开个人资料

Facebook Messenger API pages_messaging 权限

facebook-graph-api - 查询 Ads API 统计信息是否需要开始/结束时间? (如何调整夏令时)

iphone - 操作无法完成。 ( cocoa 错误 1560。)

ios - Facebook iOS sdk xcode 4.3/storyboards

android - 如何解决 Session 'app' : error?

javascript - JavaScript 函数运行时显示消息