简体   繁体   中英

iOS Facebook 4.0 SDK Share OpenGraph story with UIImage error

I am in need of posting an OpenGraph story that contains a user generated image, without requesting any permissions.

I have followed the official tutorial posted here: https://developers.facebook.com/docs/sharing/opengraph/ios

And here is my code:

NSDictionary *properties = @{@"og:type": @"minidraw-two.illustration",
                                     @"og:title": @"Illustration",
                                     @"og:description": @"iOS Vector illustration app"};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];

// Construct an FBSDKSharePhoto
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image;
photo.userGenerated = YES;

FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"minidraw-two.create" object:object key:@"minidraw-two:illustration"];
[action setPhoto:photo forKey:@"image"];

FBSDKShareOpenGraphContent *content = [FBSDKShareOpenGraphContent new];
content.action = action;
content.previewPropertyName = @"minidraw-two:illustration";

[FBSDKShareDialog showFromViewController:viewController
                                     withContent:content
                                        delegate:self];

When posting this content, I am getting the following error:

Error Domain=com.facebook.Facebook.platform Code=100 "The operation couldn't be completed. (com.facebook.Facebook.platform error 100.)" UserInfo=0x174070f00 {error_reason=Missing either 'type' or 'fbsdk:create_object' for object: image, error_description=An error occurred while sharing an action., app_id=, error_code=100}

I am not really sure what this error means. I have checked StackOverflow, the Facebook docs and found nothing.

Please advice.

After reading this FB bug report , I've got the photo to be shared without any errors. The key is to attach the photo to the Open Graph object rather than the action .

// Add the photo to the OG object
[object setPhoto:photo forKey:@"og:image"];

The photo is still not showing full-width, but that has been recognized by FB as a valid bug in v4.0.1 and I will update this answer as soon as I hear more from them.

UPDATE: According to FB, it is by design that photos will not show full-width on Open Graph stories.

If You change

[FBSDKShareDialog showFromViewController:viewController withContent:content delegate:self];

to

[FBSDKShareAPI shareWithContent:content delegate:self];

and use your old variant [action setPhoto:photo forKey:@"image"]; the code will also work

2 fatuhoku - on my opinion use FBSDKShareAPI is better because 1) your app does not switch to FB app to present dialog 2) you control all the data you want to share/post in FB from your app. For example my app shares only it's internal data and i don't want user to add comment to it in the dialog. 3) you keep the UI style of your app for example screen colors but FB dialogs has there own. Yes, you should do more work then when using FBSDKShareDialog but read what i say above ;)

This has been fixed. Both FBSDKShareDialog and FBSDKShareAPI work the same now. Relevant bug report here . Official docs updated as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM