ShareKit - posting linked image to facebook wall

杀马特。学长 韩版系。学妹 提交于 2019-11-30 07:41:46

(answering my question)

I changed the file SHKfacebook.m changing the dialog.attachment line to read:

dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@\",\"href\"
:\"%@\",\"media\":[{\"type\":\"image\",\"src\":\"http://example.com/example.png\"
,\"href\": \"http://example.com/\"}]} ",item.title == nil ? SHKEncodeURL(item.URL) 
SHKEncode(item.title),SHKEncodeURL(item.URL)];

(make it one line after you paste in)

You can see there is an image url - http://example.com/example.png - which should be about 76 X 90px, and a link url - http://example.com/

You may also need to explicitly set the sharetype. I've noticed on 3G/3GS iPhones then it doesn't work unless you do this:

item.shareType = SHKShareTypeURL;
[SHKFacebook shareItem:item];
SHKFacebook * sharer = [ [ [ SHKFacebook alloc ] init] autorelease ];
SHKItem * item = [ SHKItem URL:[ NSURL URLWithString:@"http://google.com" ]
                         title:@"my title"
                   contentType:SHKURLContentTypeUndefined ];
item.facebookURLShareDescription = @"my description";
item.facebookURLSharePictureURI = @"http://www.userlogos.org/files/logos/pek/stackoverflow.png";
[ sharer loadItem:item ];
[ sharer share ];

Here is my amendment for the answer and it can share the title, image and the description when share to facebook. Enjoy it

dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@\",\"href\":\"%@\",\"description\":\"%@\",\"media\":[{\"type\":\"image\",\"src\":\"http://4.bp.blogspot.com/-77BXdZj0M6o/Tr0t9pndpOI/AAAAAAAAAQ4/j3KWIE9ov1E/s1600/Blue_Eye_by_SapphiraBlue.jpg\" ,\"href\": \"%@/\"}]} ",item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title),SHKEncodeURL(item.URL), @"Testing Description Comes Here", SHKEncode(SHKMyAppURL)];

Or another solution comes here for editing the image and description as parameters

dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@\",\"href\":\"%@\",\"description\":\"%@\",\"media\":[{\"type\":\"image\",\"src\":\"%@\" ,\"href\": \"%@/\"}]} ",item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title),SHKEncodeURL(item.URL), item.text, item.filename, SHKEncode(SHKMyAppURL)];
dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:");
dialog.defaultStatus = @"";

By passing the parameters simply like this:

SHKItem *itemfb = [SHKItem image:@"" title:@"TITLE" url:url2];
        itemfb.shareType = SHKShareTypeURL;
        itemfb.text = @"DESCRIPTION COME HERE"; 
        itemfb.filename = @"IMAGE PATH";
        [SHKFacebook shareItem:itemfb];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!