查找哪些朋友喜欢特定对象



我正在使用以下图形 API 请求来获取所有喜欢特定对象的朋友:

me/?fields=friends.fields(likes.target_id(searched_object_id))

iOS代码如下:

[ FBRequestConnection startWithGraphPath: [ NSString stringWithFormat: @"me/?fields=friends.fields(name,likes.target_id(%lld))", 7919071058 ]
                 completionHandler: ^(FBRequestConnection *connection, id result, NSError *error) {
                     [ [ [ result objectForKey: @"friends" ] objectForKey: @"data" ] enumerateObjectsUsingBlock:^(id friend, NSUInteger idx, BOOL *stop) {
                         if ( [ friend objectForKey: @"likes" ] )
                             NSLog( @"%@ also likes that", [ friend objectForKey: @"name" ] );
                     } ];
                 }
 ];

我想对 og.likes 做同样的事情,不幸的是.target_id

不可用

有关信息,og.likes 是可以在应用程序中声明的开放图形对象 https://developers.facebook.com/docs/opengraph/tutorial/。

提前感谢您的帮助

这里按照修改后的代码来处理 og.likes

[ FBRequestConnection startWithGraphPath: @"me/?fields=friends.fields(name,og.likes)"
                     completionHandler: ^(FBRequestConnection *connection, id result, NSError *error) {
                         [ [ [ result objectForKey: @"friends" ] objectForKey: @"data" ] enumerateObjectsUsingBlock:^(id friend, NSUInteger idx, BOOL *stop) {
                             [ [ [ friend objectForKey: @"og.likes" ] objectForKey: @"data" ] enumerateObjectsUsingBlock:^(id ogLike, NSUInteger idx, BOOL *stop) {
                                 if ( [ [ [ [ ogLike objectForKey: @"data" ] objectForKey: @"object" ] objectForKey: @"id" ] isEqualToString: [ NSString stringWithFormat: @"%lld", idObject ] ] )
                                     NSLog( @"%@ also og.likes that", [ friend objectForKey: @"name" ] );
                             } ];
                         } ];
                     }
 ];

正如你所看到的,我必须抓住我朋友的每一个og.like,然后遍历它们以找到匹配的。它是更多的带宽,但它有效。如果有人找到一种更优雅的方式,我仍然对此感到好奇。

问候

相关内容

最新更新