是否可以通过Facebook SDK找到我的朋友在线状态(在线,离开或错误)?
使用FQL我可以这样做:
SELECT uid, name,pic_small,pic_big,online_presence FROM user
WHERE online_presence IN ('active') AND uid IN
(SELECT uid2 FROM friend WHERE uid1 = me())order by name
但是有没有办法在facebook SDK中做到这一点,可能会使用这样的东西:
[FBRequest requestForGraphPath:@"some/end/point/that/I/am/missing"]
任何帮助表示赞赏。感谢。
答案 0 :(得分:2)
很抱歉迟到在这里发布...我自己解决了这个问题,这是我的解决方案:
- (void)getFriendsOnlinePresence
{
NSString* fql1 = [NSString stringWithFormat:@"SELECT uid,pic_square, name,online_presence FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY name"];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
fql1, @"q",
nil];
[FBSession openActiveSessionWithAllowLoginUI:NO];
[FBRequestConnection startWithGraphPath:@"fql"
parameters:params
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
} else {
NSLog(@"Result: %@", result);
}
}
//Notify via notification center
}];
}
答案 1 :(得分:0)
如果您可以在FQL中执行此操作,那么在SDK中使用它只需要找出正确的查询。您的查询
SELECT uid, name,pic_small,pic_big,online_presence FROM user
WHERE online_presence IN ('active') AND uid IN
(SELECT uid2 FROM friend WHERE uid1 = me()) order by name
基本上graph.facebook.com/fql?q=SELECT uid, name,pic_small,pic_big,online_presence FROM user WHERE online_presence IN ('active') AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) order by name
HTTP GET /fql?q=<QUERY>
所以我认为只需要在fql
requestForGraphPath
FBRequest *fql = [FBRequest requestForGraphPath:@"fql"];
[fql.parameters setObject:@"SELECT uid, name,pic_small,pic_big,online_presence FROM user WHERE online_presence IN ('active') "
@"AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) order by name"
forKey:@"q"]
最新文档会在startWithGraphPath
FBRequestConnection
的示例
NSString *query =
@"SELECT uid, name,pic_small,pic_big,online_presence FROM user WHERE online_presence IN ('active') "
@"AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) order by name";
// Set up the query parameter
NSDictionary *queryParam = @{ @"q": query };
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:@"/fql"
parameters:queryParam
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
} else {
NSLog(@"Result: %@", result);
}
}];
来源:https://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/