iOS如何在自定义对象Graph Api上发布动作 - Facebook

时间:2015-05-06 09:00:32

标签: ios facebook-graph-api facebook-like facebook-ios-sdk

我需要发布行动

我成功发布了图表API中的“喜欢链接”。 例如'abc喜欢www.abc.com'

现在我被困在'喜欢自定义对象',例如'abc likes toy1' 并获得喜欢的总数。

这是不起作用的示例代码

       NSDictionary *properties = @{
                                     @"og:type": @"toy",
                                     @"og:title": @"toy1",
                                     @"og:description": @"This is a sample course."};    
       FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
        FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
        action.actionType = @"og.likes";
        [action setObject:object forKey:@"toy"];
        FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
        content.action = action;
        content.previewPropertyName = @"toy";
        FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
        // optionally set the delegate
         shareAPI.delegate = self;
        shareAPI.shareContent = content;
        [shareAPI share];

编辑:我的代码正在改变

toy

appnamespace:toy

[action setObject:object forKey:@"toy"]; // to  [action setObject:object forKey:@"object"];

现在我想获取此自定义对象上的总喜欢次数

1 个答案:

答案 0 :(得分:0)

A" og:type" "玩具"无效。它应该是一个常见的OG类型(如" fitness.course")或自定义的(#34; yourappnamespace:玩具")。

如果您只是喜欢网站或其他网址,则可以跳过OG对象并创建

之类的操作
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"og.likes"
                                                                    objectURL:[NSURL URLWithString:@"http://www.example.com"]
                                                                          key:@"og:object"];

(请注意,如果你尝试两次相同的东西,它会给你一个错误。)

您应该确保您的委托实现- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error以接收错误信息。

您可能还想使用FBSDKLikeButton or FBSDKLikeControl