使用 FBSDKShareOpenGraphObject 将文章分享到 Facebook 后看不到图像
Not see image after shared article to Facebook with FBSDKShareOpenGraphObject
我尝试将图片分享到 Facebook,我需要应用程序名称在 Facebook 的共享 post 中
这是代码:
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
UIImage *image1 = [GeneralMethods imageConvertToSizeWithImage:postImageView.image scaledToWidth:300];
photo.image = [UIImage imageNamed:@"VImage.png"];
photo.userGenerated = YES;
NSDictionary *properties = @{
@"og:type": @"article",
@"og:title": @"new item",
@"og:description": @"bla bla",
// @"og:image": @[photo],
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// [object setPhoto:photo forKey:@"og:image"];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"news.publishes";
[action setObject:object forKey:@"article"];
// Add the photo to the action. Actions
// can take an array of images.
[action setArray:@[photo] forKey:@"image"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";
[FBSDKShareDialog showFromViewController:ParetDelaget withContent:content delegate:self];
这是我添加图片的 Facebook 预览页面:
这是我 Facebook 墙上的 post 没有图像 :
我做错了什么?
取消注释此行:
// @"og:image": @[photo],
并评论这个:
[action setArray:@[photo] forKey:@"image"];
像这样,您将同时显示图片、标题和描述。
注意一点:照片object必须是字符串URL
在我的例子中,这是结果代码:
// Create an object
NSDictionary *properties = @{
@"og:type": @"article",
@"og:url": @"https://the_link_you_want.com",
@"og:title": @"your title",
@"og:description": @"your description",
@"og:image": @"http://url_to_your_image"
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"news.publishes";
[action setObject:object forKey:@"article"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
[shareDialog show];
if (![shareDialog canShow]) {
// update the app UI accordingly
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
NSLog(@"FB Error: %@", error);
}
希望对您有所帮助
我尝试将图片分享到 Facebook,我需要应用程序名称在 Facebook 的共享 post 中
这是代码:
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
UIImage *image1 = [GeneralMethods imageConvertToSizeWithImage:postImageView.image scaledToWidth:300];
photo.image = [UIImage imageNamed:@"VImage.png"];
photo.userGenerated = YES;
NSDictionary *properties = @{
@"og:type": @"article",
@"og:title": @"new item",
@"og:description": @"bla bla",
// @"og:image": @[photo],
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// [object setPhoto:photo forKey:@"og:image"];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"news.publishes";
[action setObject:object forKey:@"article"];
// Add the photo to the action. Actions
// can take an array of images.
[action setArray:@[photo] forKey:@"image"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";
[FBSDKShareDialog showFromViewController:ParetDelaget withContent:content delegate:self];
这是我添加图片的 Facebook 预览页面:
这是我 Facebook 墙上的 post 没有图像 :
我做错了什么?
取消注释此行:
// @"og:image": @[photo],
并评论这个:
[action setArray:@[photo] forKey:@"image"];
像这样,您将同时显示图片、标题和描述。
注意一点:照片object必须是字符串URL
在我的例子中,这是结果代码:
// Create an object
NSDictionary *properties = @{
@"og:type": @"article",
@"og:url": @"https://the_link_you_want.com",
@"og:title": @"your title",
@"og:description": @"your description",
@"og:image": @"http://url_to_your_image"
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"news.publishes";
[action setObject:object forKey:@"article"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
[shareDialog show];
if (![shareDialog canShow]) {
// update the app UI accordingly
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
NSLog(@"FB Error: %@", error);
}
希望对您有所帮助