[英]how to post URL with Image on facebook by ShareKit
我在我的iPhone应用程序中使用sharekit在Facebook上分享网址链接。 但是,在我看来,不可能与sharekit共享图像的URL。 你们知道怎么做吗? 非常感谢。
请查看我在SHKFacebook.m / h文件中创建自己的Send方法的代码,我认为它会对您有所帮助。
-(BOOL) sendWithImage :(NSString*)creativeUrl
{
self.pendingFacebookAction = SHKFacebookPendingStatus;
SHKFBStreamDialog* dialog = [[[SHKFBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:");
dialog.attachment = [NSString stringWithFormat:
@"{\
\"name\":\"%@\",\
\"href\":\"%@\",\
\"media\":[{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"}]\
}",
item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title),
SHKEncodeURL(item.URL),
creativeUrl,
SHKEncodeURL(item.URL)
];
dialog.defaultStatus = item.text;
dialog.actionLinks = [NSString stringWithFormat:@"[{\"text\":\"Get %@\",\"href\":\"%@\"}]",
SHKEncode(SHKMyAppName),
SHKEncode(SHKMyAppURL)];
[dialog show];
return YES;
}
这是我如何使用它
SHKFacebook *fb =[[SHKFacebook alloc]init];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@iphone/photo?id=%d",[SplashViewController getBaseURL],[photoId intValue]]];
fb.item = [SHKItem URL:url title:[dicResult valueForKey:@"Caption"]];
//fb.shareType = SHKShareTypeURL;
fb.quiet = YES;
[TedryUITabBarController updateProgress:10 totalByteToSent:11 message:@"Sharing on facebook"];
[fb sendWithImage:[dicResult valueForKey:@"CreativeURL"] :@""];
对于那些在这里遇到其他答案问题的人(虽然原则上基本相同),这可能会稍微简单一点。
将自定义值添加到项目中,例如:
[item setCustomValue:@"Your caption" forKey:@"caption"];
[item setCustomValue:@"Your description" forKey:@"description"];
[item setCustomValue:@"Your image URL" forKey:@"mediaSrc"];
[item setCustomValue:@"Your image link" forKey:@"mediaHREF"];
请注意底部图像所需的两个值:源URL和链接URL。 然后,您需要修改SHKFacebook.m中的“send”方法以使用这些值,如下所示:
// ...
if (item.shareType == SHKShareTypeURL)
{
self.pendingFacebookAction = SHKFacebookPendingStatus;
SHKFBStreamDialog* dialog = [[[SHKFBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:");
// with image...
dialog.attachment = [NSString stringWithFormat:
@"{\
\"name\":\"%@\",\
\"href\":\"%@\",\
\"caption\":\"%@\",\
\"description\":\"%@\",\
\"media\":[\
{\
\"type\": \"image\",\
\"src\": \"%@\",\
\"href\": \"%@\"\
}]\
}",
item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title),
SHKEncodeURL(item.URL),
[item customValueForKey:@"caption"],
[item customValueForKey:@"description"],
[item customValueForKey:@"mediaSrc"],
[item customValueForKey:@"mediaHREF"]
];
dialog.defaultStatus = item.text;
dialog.actionLinks = [NSString stringWithFormat:@"[{\"text\":\"Get %@\",\"href\":\"%@\"}]",
SHKEncode(SHKMyAppName),
SHKEncode(SHKMyAppURL)];
[dialog show];
}
// ...
jumponadoughnut给出的链接是你可以使用的最终字段列表(我无法投票,因为我的代表不够高): http : //developers.facebook.com/docs/guides/attachments
我正在使用github的最新sharekit。 实际上,您只需将网址设置为链接的自定义值,并使用关键字“图片”
NSString *urlImage = @"http://someurl.com/someimage.jpg";
[linkItem setCustomValue:urlImage forKey:@"picture"];
这个对我有用。
您需要在[SHKFacebook send:]实现中找到的附件json NSString中包含媒体URL。 请参阅http://developers.facebook.com/docs/guides/attachments
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.