5

是否可以使用 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"]

任何帮助表示赞赏。谢谢。

4

2 回答 2

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
                      }];

}
于 2013-07-30T06:18:04.100 回答
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/

于 2013-07-27T20:57:42.417 回答