In iOS Facebook SDK 3.5, there is supposedly a way to create a new story with the open graph API without needing a back-end server.
The documentation/tutorials on Facebook.com only show how it is done with a back-end server, and there seems to be no working code on the internet that I can find on how to do so.
I have managed to put together the following code based on small snippets of code but it does not work:
NSMutableDictionary<FBOpenGraphObject> *event = [FBGraphObject openGraphObjectForPost];
event[@"type"] = @"leaf-events:event";
event[@"title"] = @"Adam's Birthday";
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject openGraphActionForPost];
action[@"event"] = event;
[FBRequestConnection startForPostWithGraphPath:@"me/leaf-events:create"
graphObject:action
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(@"Result: %@", result);
NSLog(@"Error: %@", error.userInfo);
}];
This code crashes and tells me:
2013-06-19 19:40:01.451 Events[1150:60b] Error: {
"com.facebook.sdk:ErrorSessionKey" = "<FBSession: 0x1650fe80, state: FBSessionStateOpen, loginHandler: 0x1651dc20, appID: 474218799329968, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x16549810>, expirationDate: 4001-01-01 00:00:00 +0000, refreshDate: 2013-06-19 18:39:57 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(\n \"basic_info\"\n)>";
"com.facebook.sdk:HTTPStatusCode" = 400;
"com.facebook.sdk:ParsedJSONResponseKey" = {
body = {
error = {
code = 3503;
message = "(#3503) \"{\"type\":\"leaf-events:event\",\"data\":{},\"title\":\"Adam's Birthday\",\"fbsdk:create_object\":true}\" is an invalid value for property \"event\" with type \"Reference\"";
type = OAuthException;
};
};
code = 400;
};
}
Can anyone help me and provide sample code on how to do this seemingly simple task, I've been stuck on it for 2 days straight now!
i see that this is old question - but there are still no good answers - so i hope to help smb. create object:
- (NSDictionary *)sharingDictionaryForXXX {
return @{
@"type" : @"app_namespace:object_name",
@"fbsdk:create_object" : @YES,
@"title" : "title text",
@"url" : @"link to your site configured in app dashboard",
@"image" : @"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png",
@"description" : "your description",
};
}
share:
id<FBOpenGraphAction> action = [FBGraphObject openGraphActionForPost];
action[@"object_name"] = [self sharingDictionaryForXXX];
FBOpenGraphActionShareDialogParams * params = [[FBOpenGraphActionShareDialogParams alloc] init];
params.actionType = @"app_namespace:action_name";
params.action = action;
params.previewPropertyName = @"object_name";
// Show the Share dialog if available
if ([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
[FBDialogs presentShareDialogWithOpenGraphAction:[params action]
actionType:[params actionType]
previewPropertyName:[params previewPropertyName]
handler:^(FBAppCall * call, NSDictionary * results, NSError * error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"Success!");
}
}];
} else {
// If the Facebook app isn't available, show the Feed dialog as a fallback
[self presentWebBasedSharing];
}
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.