我必须在我的应用程序中使用从 v3.x 到 v4.x 的 Facebook SDK 替换。当它使用旧 sdk 和下一个代码时:
NSString *msg = [NSString stringWithFormat:@"%@\n%@\n%@", petition.petition_name, petition.recipient, petition.content];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
msg, @"message",
petition.uri ? petition.uri : [NSURL URLWithString:SITE], @"link",
nil
];
NSLog(@"%@\n%@", msg, params);
[FBRequestConnection startWithGraphPath:@"me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
. . . .
}];
分享帖子时字符串变量msg传递文本消息:
在 Facebook SDK 4.x 中有一个特殊的对话框,它没有任何字段或功能用于此类任务。我使用下一个代码(即使使用 og:- params - 即使我尝试过 og:message),但我的帖子出现时没有任何消息:
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [self.pdata.imagesArr firstObject];
// Optionally set user generated to YES only if this image was created by the user
// You must get approval for this capability in your app's Open Graph configuration
// photo.userGenerated = YES;
NSString *urlStr = [NSString stringWithFormat:@"%@/api/images/%@?width=%f&height=%f&x=0&y=0&resize=1", K_BASE_URL, [[self.pdata.imagesArr firstObject] image_id], K_PETITION_IMAGE_WIDTH, K_PETITION_IMAGE_HEIGHT];
// Create an object
NSDictionary *properties = @{
@"og:type": @"books.book",
@"og:title": self.pdata.petition_name,
@"og:description": self.pdata.content,
@"og:image": urlStr,
@"og:url": [NSURL URLWithString:self.pdata.uri],
@"og:message": @"QQQQQQQWW",
@"books:isbn": @"0-553-57340-3",
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"books.reads";
[action setObject:object forKey:@"books:book"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"books:book";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
此消息只能从系统 facebook 对话框 ShareDialog 传递到墙上,但用户必须手动输入消息:
所以我有两个问题:
1) 即使没有这个 FBSDKShareDialog,我也可以分享我的帖子吗?可能吗?
2)如果 first == false - 如何以编程方式通过对话框传递消息?
提前致谢!