我正在尝试在 iOS 上将 OpenGraph 故事发布到 Facebook。我一直在关注本教程。
https://developers.facebook.com/docs/ios/open-graph/
我也一直在参考
我可以将帖子上传到 FB,但图像丢失。我尝试了几种变体,但发现文档很少。任何见解将不胜感激:
UIImage *loadedImage = [UIImage imageWithContentsOfFile:file];
NSArray* image = @[@{@"url":loadedImage, @"user_generated": @"true"}];
id<FBGraphObject> objectname =
[FBGraphObject openGraphObjectForPostWithType:@"namespacename:objectname"
title:@"objectname"
image:nil
url:nil
description:@"description"];
id<FBOpenGraphAction> actionname = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[actionname setObject:image forKey:@"image"];
[actionname setObject:objectname forKey:@"objectname"];
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = actionname;
params.actionType = @"namespacename:objectname";
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
[FBDialogs presentShareDialogWithOpenGraphAction:actionname
actionType:@"namespacename:actionname"
previewPropertyName:@"objectname"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// There was an error
NSLog(@"Error publishing story: %@", error.description);
} else {
// Success
NSLog(@"result %@", results);
}
}];
} else {
NSLog(@"cant show the share dialog ");
}
我已经彻底检查了代码,我能找到的唯一区别是,我不是从图库中选择图像,而是从文件中加载它。正如我所提到的,该帖子通过并在 Facebook 上共享,但是该图像既不会出现在提要上,也不会出现在新闻提要上的可点击对象中。当共享对话框加载时,我可以看到图像的缩略图,所以我相信它加载正常。任何帮助,将不胜感激。提前致谢。