how to post URL with Image on facebook by ShareKit
Asked Answered
D

4

10

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.

Damien answered 14/1, 2011 at 18:22 Comment(0)
M
11

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"] :@""]; 
Molton answered 30/1, 2011 at 13:20 Comment(2)
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!Levinson
Youve missed out big chunks of your code, so it's impossible to work how you've solved itOverunder
A
5

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

Alsacelorraine answered 9/12, 2011 at 1:19 Comment(1)
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'tGoodin
O
4

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.

Ora answered 19/7, 2011 at 7:59 Comment(1)
Looking at the source code: you need to set SHKShareTypeURL = SHKShareTypeURL and set item.URL. Worked well for me.Decent
U
3

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

Uncle answered 24/1, 2011 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.