我正在使用以下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/)
先谢谢你的帮助
答案 0 :(得分: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,然后遍历它们以找到匹配的那个。这是更多的带宽,但它的工作原理。 如果有人找到更优雅的方式,我仍然很好奇。
此致