I am using sharekit in my iPhone app to share url link on facebook. However, it seems to me that it is not possible to share url with image with sharekit. Do you guys know how to do it? Thanks a lot.
4 Answers
Please have a look to the code I just made my own Send method in SHKFacebook.m/h files, I think it will help you.
-(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;
}
Here is How I Use it
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"] :@""];

- 12,720
- 7
- 52
- 72

- 388
- 1
- 3
- 12
-
scompt, can you help me get started with your code here? where is the item? I thought sharekit is all about the item... how do i call sendWithImage - can you show a sample? Thanks! – Lior Frenkel Apr 21 '11 at 08:45
-
Youve missed out big chunks of your code, so it's impossible to work how you've solved it – daihovey Sep 29 '11 at 13:05
This may be slightly simpler, I hope, for those having problems with other answers here (although basically the same in principle).
Add the custom values to your item, such as:
[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"];
Note the two values needed for the image at the bottom: the source URL and the link URL. You then need to modify the "send" method in SHKFacebook.m to use those values, as follows:
// ...
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];
}
// ...
And the link given by jumponadoughnut is the definitive list of fields you can use (I could not vote his up because my rep is not high enough): http://developers.facebook.com/docs/guides/attachments

- 121
- 2
- 3
-
you should also escape these custom values with SHKEncode or SHKEncodeURL or via other means, because you can end up with invalid JSON data if you don't – PetrV Dec 23 '11 at 22:59
I'm using the latest sharekit from github. Actually, you just set the url as the custom value of the link, with key "picture"
NSString *urlImage = @"http://someurl.com/someimage.jpg";
[linkItem setCustomValue:urlImage forKey:@"picture"];
It works for me.

- 900
- 1
- 9
- 23
-
Looking at the source code: you need to set `SHKShareTypeURL = SHKShareTypeURL` and set `item.URL`. Worked well for me. – Chris Nolet Mar 26 '12 at 07:05
You need to include a media url in the attachment json NSString found in the [SHKFacebook send:] implementation. See http://developers.facebook.com/docs/guides/attachments

- 125
- 7