1

我正在尝试根据他朋友的性别和pic_big!=NULL(每个朋友都应该有一张大的个人资料图片)来获取用户的朋友(登录到他的 Facebook 帐户)。

下面是我正在编写的代码。

NSString *queryString =  [NSString stringWithFormat:@"%@%@%@%@%@%@%i%@%@",
                          @"SELECT name, pic_big, sex, uid FROM user ", 
                          @"WHERE sex=", @"male", @" AND ",
                          @"pic_big != 'null' AND uid IN (SELECT uid2 ",
                          @"FROM friend WHERE uid  ", loggedInID, @" )",
                          @"ORDER BY name"];  
NSMutableDictionary *dictionary=[NSMutableDictionary 
    dictionaryWithObjectsAndKeys:queryString,@"query", nil];

[FBRequest getRequestWithParams:dictionary
                     httpMethod:@"GET" 
                       delegate:self
                     requestURL:@"fql.query"]; 

loggedINiD是用户的登录 ID。我在委托方法中没有得到任何响应。我确定我需要重新检查这个 SQL 查询。请有任何建议。

4

2 回答 2

2

您的 FQL 代码中有几个错误,为了简单起见,我添加了一个建议,您应该查询以下内容:

SELECT name, pic_big, sex, uid FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex = "male"

注意事项:

  1. uid1 是朋友表的正确索引字段,而不是 uid
  2. 您在“来自朋友 WHERE uid”之后缺少等号
  3. me() 是 FQL 中的一个辅助函数,它代表当前会话用户(即应用程序用户)
  4. pic_big 永远不会为空,因为即使是 Facebook 上用户的默认个人资料图片也会为此返回一个值,因此对其进行测试是多余的。
  5. 我改变了 WHERE 子句的顺序,但这不重要。
于 2011-09-05T11:41:55.880 回答
0
NSString *queryString =  [NSString stringWithFormat:@"SELECT name, pic_big, sex, uid FROM user WHERE sex='male' AND pic_big != 'null' AND uid IN (SELECT uid2 FROM friend WHERE uid = %i) ORDER BY name", loggedInID];  

使用此查询字符串。我不确定,但认为这会对您有所帮助。

于 2011-09-05T11:41:14.693 回答