Fb分享对话框,我可以简单地发布一张带有描述的图片吗?
Posted
技术标签:
【中文标题】Fb分享对话框,我可以简单地发布一张带有描述的图片吗?【英文标题】:Fb share dialog, can i simply post a picture with a description? 【发布时间】:2015-01-14 09:06:16 【问题描述】:我正在尝试为我的 ios 应用程序创建一个简单的共享功能。我想利用新的共享对话框(优点,例如,标记朋友,添加地点,ecc..)。我想分享的是一张照片,一个iTunes应用下载的链接,一个来自ios应用的描述。我已经尝试过共享对话框,如下所示:
NSURL *url=[[NSURL alloc] initWithString:@"https://itunes.apple.com/it/app/myapplication"];
[FBDialogs presentShareDialogWithLink:url name:@"My app name" caption:@"" description:@"prefilled descriptiontest" picture:[NSURL URLWithString:@"http://www.example.com/image.jpg"] clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error)
if(error)
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
UIAlertView *av = [[[UIAlertView alloc]
initWithTitle:@"Sorry :("
message:@"There's been a problem publishing your message. Please try again!"
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:nil] autorelease];
[av show];
else
// Success
UIAlertView *av = [[[UIAlertView alloc]
initWithTitle:@"Published!"
message:@"Your post has been successfully published."
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:nil] autorelease];
[av show];
];
它有效,但我只在共享对话框中看到我的预填充描述,当我在 facebook 上看到共享内容时,我只看到从链接页面获取的描述。所以我尝试了另一种解决方案,照片对话框:
UIImage *Image=[UIImage imageNamed:@"myphoto.jpg"];
// Open the image picker and set this class as the delegate
FBPhotoParams *params = [[FBPhotoParams alloc] init];
// Note that params.photos can be an array of images. In this example
// we only use a single image, wrapped in an array.
params.photos = @[Image];
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call,
NSDictionary *results,
NSError *error)
if (error)
NSLog(@"Error: %@",
error.description);
else
NSLog(@"Success!");
];
这样我可以在我的墙上贴一张照片,但描述参数似乎是只读的,我无法设置任何预填充文本。我该怎么办?有一种方法可以强制在共享链接对话框中显示我的描述文本?或者有一种方法可以在照片对话框中设置文本?还是有其他解决方案?
【问题讨论】:
不允许预充,请阅读平台政策:developers.facebook.com/policy 我不想预填充用户可以在共享对象上方插入的文本,我想在图像旁边添加描述文本,有名为描述和标题的参数。 【参考方案1】:唯一的解决方案似乎是只使用网络后备:
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithObjectsAndKeys:
name, @"name",
author, @"caption",
linkShare, @"link",
userImage, @"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:parameter
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
if (error)
NSLog(@"Error publishing story: %@", error.description);
else
if (result == FBWebDialogResultDialogNotCompleted)
NSLog(@"User cancelled.");
else
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
NSLog(@"User login");
if (![urlParams valueForKey:@"post_id"])
NSLog(@"User cancelled post.");
else
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
NSLog(@"result %@", result);
];
【讨论】:
以上是关于Fb分享对话框,我可以简单地发布一张带有描述的图片吗?的主要内容,如果未能解决你的问题,请参考以下文章