0

I would like to post an url, image and text at the same time to facebook using Sharekit in iOS. Is it possible? If so, how do I do it? Any guidance.

I would like to acheive something like this. Need some help.

I have tried something like this:

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

But doesn't seem to post with the description...

EDIT:

my facebooksharedescription and facebookshareuri looks like this:

- (NSString *)facebookURLSharePictureURI {
    return nil;
}

- (NSString *)facebookURLShareDescription {
    return nil;
}

Do I need to change anything in this.

When i change to forcepreIOS6posting,it gives me this error:

the operation cannot be completed.(com.facebook.sdk. error 2.)

Need some guidance on these two as well...

lakshmen
  • 28,346
  • 66
  • 178
  • 276

2 Answers2

2

see sharer specific extensions in SHKItem.h and DefaultSHKConfigurator.m in ShareKit 2.0. It is clearly described there.

You can set link, image and description + user can add some message if you decide to present the dialogue to user.

Note, that this works on ShareKit type of sharing dialogue (pre iOS6). On iOS6 ShareKit uses new native social.framework dialogue, where this type of behaviour is not possible. You can force pre-iOS6 behaviour even on iOS 6 in your configurator subclass (again, for more info check DefaultSHKConfigurator.m.

If you decide to use ShareKit, make sure to follow sharekit install wiki literally.

EDIT: this is pasted from ShareKit sample app, ExampleShareLink.m file. It is a content type video, but you can use these facebook sharer specific extensions for any content type.

SHKItem *item = [SHKItem URL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=3t8MeE8Ik4Y"] title:@"Big bang" contentType:SHKURLContentTypeVideo];
item.facebookURLSharePictureURI = @"http://www.state.gov/cms_images/india_tajmahal_2003_06_252.jpg";
item.facebookURLShareDescription = @"description text"; 

EDIT 2: if you followed wiki carefully, you got to the point 4 - Configuration. In your configurator subclass, override

- (NSNumber*)forcePreIOS6FacebookPosting {
    return [NSNumber numberWithBool:false];
}

and set to true. You can configure (override) many other things, see DefaultSHKConfigurator.m

Vilém Kurz
  • 3,401
  • 2
  • 34
  • 43
  • i am following sharekit.. it would be nice if you could show an example...it will be useful for the rest as well... – lakshmen Dec 06 '12 at 17:32
  • On iOS6 ShareKit uses new native social.framework dialogue, where this type of behaviour is not possible. You can force pre-iOS6 behaviour even on iOS 6 in your configurator subclass (again, for more info check DefaultSHKConfigurator.m. Hw to do this? – lakshmen Dec 07 '12 at 03:33
  • ok.. thanks first of all.. I have changed it to forcePreIOS6Posting but when i post to facebook, I get this error: The operation cannot be completed.(com.facebook.sdk.error.2). How do solve this? – lakshmen Dec 07 '12 at 15:16
  • Well, this error is rare, but known, unfortunately no solution yet. It happens sometimes when authentification is messed. Try again after logging off the user from facebook. If this does not help, delete the app and run again. You can follow [this thread](https://github.com/ShareKit/ShareKit/issues/596) for updates on the issue. – Vilém Kurz Dec 07 '12 at 15:52
  • how the facebookURLSharePictureURI method? – lakshmen Dec 07 '12 at 16:18
  • question? how about the facebookURLSharePictureURI method? is the implementation right? or do i have to change anything... – lakshmen Dec 07 '12 at 17:56
  • OK, I got it. In configurator you only set the default behaviour. So if you wish to set the same default picture for all shares, set it in configurator (). If you expect the picture be different for each single share action, set it as in my code snippet for each shared item separately. In this case you do not need to override the method in your configurator. – Vilém Kurz Dec 07 '12 at 17:56
  • btw, I am the one who created the thread you passed me... so still it is not solved. – lakshmen Dec 12 '12 at 10:20
  • if u dun mind, could you help me out? really need someone to look into the error.. – lakshmen Dec 12 '12 at 11:19
  • sorry, I can not help with this at the moment. – Vilém Kurz Dec 12 '12 at 11:20
0

If you don't want to focePreIOS6FacebookPosting you can set the SHKItem's image property. The problem with this is it wants an actual UIImage object and not a URL.

You can create a UIImage object synchronously or use a UIImage object you already have loaded with an image for sharing:

NSURL* aURL = [NSURL URLWithString:photoURL];
NSData* data = [[NSData alloc] initWithContentsOfURL:aURL];
item.image = [UIImage imageWithData:data];

I solved the error com.facebook.sdk.error.2 by setting the correct bundle id in my Facebook app settings. I was using a different bundle ID for testing so the bundle id in my Facebook app settings did not match my app's bundle id and I got the com.facebook.sdk.error.2 issue. This was solved by adding the additional development bundle id to the Facebook app settings.

jbolter
  • 169
  • 2
  • 7