在iOS Facebook SDK 3.5中,有一种方法可以使用开放图形API创建新故事而无需后端服务器。
Facebook.com上的文档/教程仅显示了如何使用后端服务器,并且在互联网上似乎没有关于如何操作的工作代码。
我已经设法根据代码的小片段汇总了以下代码,但它不起作用:
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);
}];
此代码崩溃并告诉我:
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;
};
}
任何人都可以帮助我并提供有关如何完成这项看似简单的任务的示例代码,我已经连续两天坚持了!
答案 0 :(得分:0)
我发现这是一个老问题 - 但仍然没有好的答案 - 所以我希望能帮助smb。 创建对象:
- (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",
};
}
份额:
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];
}