I need to publish Open Graph story to Facebook wall from my app. I followed current tutorial on Facebook developers.
I've created object,action and story on Facebook dashboard. Then in my app do the following code:
create an object:
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[@"title"] = @"test title";
object[@"type"] = @"myapp:my_object_type";
object[@"description"] = @"test discription";
object[@"url"] = @"http://example.com";
object[@"image"] = @[@{@"url": [result objectForKey:@"uri"], @"user_generated" : @"false" }];
and post it:
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSString *objectId = [result objectForKey:@"id"];
NSLog(@"object id %@",objectId);
} else {
NSLog(@"Error posting the Open Graph object to the Object API: %@", error);
}
}];
} else {
NSLog(@"Error staging an image: %@", error);
}
}];
Got object id as result.
Then create an action and link it with object:
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:@"my_object_type"];
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = @"myapp:my_app_action";
And post it to Facebook:
[FBRequestConnection startForPostWithGraphPath:@"/me/myapp:my_app_action" 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 {
NSLog(@"Encountered an error posting to Open Graph: %@", error);
}
}];
As a result i got the message that OG story was successfully posted, but when going to Facebook, there is nothing in feed or timeline, just an image added to users photo album.
Well, dunno what was the problem, but now it works with the following code: