朋友在线状态 - Facebook SDK 3
Posted
技术标签:
【中文标题】朋友在线状态 - Facebook SDK 3【英文标题】:Friends Online Presence - Facebook SDK 3 【发布时间】:2013-07-05 11:56:31 【问题描述】:是否可以使用 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"]
任何帮助表示赞赏。谢谢。
【问题讨论】:
我也有同样的问题 【参考方案1】:很抱歉在这里发布它迟到了......我自己解决了这个问题,这是我的解决方案:
- (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
];
【讨论】:
【参考方案2】:如果您可以在 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>
所以我相信只需要在requestForGraphPath
中将路径设置为fql
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"]
最新的文档虽然在FBRequestConnection
下显示了带有startWithGraphPath
的示例
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/
【讨论】:
以上是关于朋友在线状态 - Facebook SDK 3的主要内容,如果未能解决你的问题,请参考以下文章
Facebook Graph API:如何获得在线朋友/或最后 X 分钟活跃
使用 Facebook Javascript SDK 检查在线用户