在目标c中获取来自facebook的计数和评论详细信息

时间:2014-04-15 08:39:35

标签: ios objective-c facebook facebook-graph-api

我正在尝试从like访问特定共享的comments次和Facebook

建议我检索like count及其评论的方法。

现在我正在获取特定分享的帖子ID ....

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                           @"http://samples.ogp.me/XXXXXXXXXX", @"object",
                           nil
                       ];

[FBRequestConnection startWithGraphPath:@"/me/og.likes"
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(
                          FBRequestConnection *connection,
                          id result,
                          NSError *error
                      ) {

                      }];

但我没有得到任何回应

请帮帮我......

1 个答案:

答案 0 :(得分:0)

我通常使用此解决方案来获得喜欢计数:

NSString *likesRequestURL = [[NSString stringWithFormat:@"https://graph.facebook.com/fql?q=SELECT+total_count,+url+FROM+link_stat+WHERE+url+=\"%@\"&access_token=%@", URL, FBSession.activeSession.accessTokenData.accessToken ? FBSession.activeSession.accessTokenData.accessToken : self.fbToken] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:likesRequestURL]
                                                       cachePolicy:NSURLRequestReloadIgnoringCacheData
                                                   timeoutInterval:60.0f];

__block NSString *result = [NSString string];

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                           if (error == nil) {
                               NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                               SBJsonParser *jsonParser = [[[SBJsonParser alloc] init] autorelease];
                               result = [NSString stringWithFormat:@"%@", [[[[jsonParser objectWithString:jsonString] objectForKey:@"data"] objectAtIndex:0] objectForKey:@"total_count"]];
                               [jsonString release];
                           } else {
                               NSLog(@"Error = %@", error);
                           }
                       }];

有效。

P.S。:我使用SBJSONParser,但是如果你想使用其他的,只需更改相应的代码,这很容易。