FB帖子的喜欢数量

时间:2013-07-29 07:58:25

标签: ios facebook facebook-like

在我的应用程序中,我想明确显示任何特定帖子的喜欢数量。是否有API调用可以使用FaceBook的POST ID获取此信息?

2 个答案:

答案 0 :(得分:2)

使用FB对象调用新请求:

[facebook requestWithGraphPath:@"ID/likes"];

ID替换为您感兴趣的帖子的Facebook ID。此调用将返回一个包含该照片所有相似信息的数组。

-facebook requestDidLoad:方法中,只需获取该数组的计数即可返回喜欢的数量。

NSInteger likeCount = [result count];

答案 1 :(得分:0)

我自己找到了解决方案。这就是我的做法

- (IBAction)likes_count:(id)sender {

    [self requestGraph: @"123456789876543?fields=likes.limit(1000)" sender:^(int count) {

        textView.text = [NSString stringWithFormat:@"%d", count];
        likesCount = 0;

    }];

}

-(void)requestGraph: (NSString*) fbRequest sender: (void (^)(int count))callback {

    likes_count.enabled = FALSE;
    FBRequest *like = [FBRequest requestForGraphPath:fbRequest];

    [like startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)  {

        if(likesCount == 0)
            likesCount = [result [@"likes"][@"data"]  count];
        else
            likesCount = likesCount + [result [@"data"]  count];


        if (result [@"likes"][@"paging"] [@"next"] != NULL) {

            [self requestGraph:[result [@"likes"][@"paging"] [@"next"] substringFromIndex:27] sender:callback ];
        }
        else if (result [@"paging"] [@"next"]  != NULL)
            [self requestGraph:[result [@"paging"] [@"next"] substringFromIndex:27] sender:callback];

        else {

            callback(likesCount);
            likes_count.enabled = TRUE;
        }

    }]; 
}