3

在iOS Facebook SDK 3.5中,可以使用開放圖形API創建新故事而不需要後端服務器。使用Facebook iOS SDK將自定義故事發布到圖形API 3.5

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; 
}; 
} 

誰能幫助我並提供關於如何做這個看似簡單的任務的示例代碼,我已經堅持了2天,直到現在!

回答

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]; 
    } 
相關問題