-1

我正在使用以下 Graph 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/

提前感谢您的帮助

4

1 回答 1

0

此处遵循修改后的代码以使用 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.likes 然后遍历他们以找到匹配的一个。这是更多的带宽,但它的工作原理。如果有人找到更优雅的方式,我仍然对此感到好奇。

问候

于 2012-10-16T12:45:19.907 回答