-1

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

4

2 回答 2

2

只需使用 FB 对象调用一个新请求:

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

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

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

NSInteger likeCount = [result count];

于 2013-07-29T08:01:53.133 回答
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;
        }

    }]; 
}
于 2013-09-12T10:09:00.093 回答