I'm trying to share a photo from my app to facebook, exactly like Instagram does by toggling on "Share on facebook", where the user result in having a beautiful large photo on his wall.
I followed exactly the "Custom Stories with Open Graph" tutorial on Facebook at: https://developers.facebook.com/docs/ios/open-graph
I even downloaded Facebook's sample project on iOS that follows the tutorial code. I copied this code and replaced the namespace, action and object with mine. Here's the code:
// stage an image
[FBRequestConnection startForUploadStagingResourceWithImage:image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(@"Successfuly staged image with staged URI: %@", [result objectForKey:@"uri"]);
// instantiate a Facebook Open Graph object
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
// specify that this Open Graph object will be posted to Facebook
object.provisionedForPost = YES;
// for og:title
object[@"title"] = @"Roasted pumpkin seeds";
// for og:type, this corresponds to the Namespace you've set for your app and the object type name
object[@"type"] = @"fbogsample:dish";
// for og:description
object[@"description"] = @"Crunchy pumpkin seeds roasted in butter and lightly salted.";
// for og:url, we cover how this is used in the "Deep Linking" section below
object[@"url"] = @"http://example.com/roasted_pumpkin_seeds";
// for og:image we assign the uri of the image that we just staged
object[@"image"] = @[@{@"url": [result objectForKey:@"uri"], @"user_generated" : @"false" }];
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
// get the object ID for the Open Graph object that is now stored in the Object API
NSString *objectId = [result objectForKey:@"id"];
NSLog(@"object id: %@", objectId);
// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:@"dish"];
// create action referencing user owned object
[FBRequestConnection startForPostWithGraphPath:@"/me/fbogsample:eat" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(@"OG story posted, story id: %@", [result objectForKey:@"id"]);
[[[UIAlertView alloc] initWithTitle:@"OG story posted"
message:@"Check your Facebook profile or activity log to see the story."
delegate:self
cancelButtonTitle:@"OK!"
otherButtonTitles:nil] show];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Encountered an error posting to Open Graph: %@", error.description);
}
}];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Encountered an error posting to Open Graph: %@", error.description);
}
}];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error staging an image: %@", error.description);
}
}];
Here's the log:
The problem is, the posts never makes it to my wall, even though the object appears created in the Objects Browser. Going to my app dashboard on developers.facebook.com and open graph, I see the story exists, but no stories have been shared even though the app says so.
What's wrong ? Help, please!