开发者

SQL Query to fetch user's Facebook friend list based upon gender

开发者 https://www.devze.com 2023-04-02 06:32 出处:网络
I am trying to fetch the friends of the user (who is logged in into his FaceBook account) based upon the gender of his friends and based upon the pic_big!=NULL (Every friend should have a big profile

I am trying to fetch the friends of the user (who is logged in into his FaceBook account) based upon the gender of his friends and based upon the pic_big!=NULL (Every friend should have a big profile picture).

Below is my code that I am writing.

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 is the user's login ID. I am not getting any response开发者_StackOverflow社区 in the delegate methods. I am sure I need to recheck this SQL query. Any suggestions please.


You have a couple of errors in your FQL code and adding one suggestion I would make for simplicity, here is what you should query instead:

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

Things to note:

  1. uid1 is the correct index field for the friend table, not uid
  2. You were missing the equals sign after "FROM friend WHERE uid"
  3. me() is a helper function in FQL which represents the current session user (ie. the app user)
  4. pic_big will never be null, as even the default Profile pic for users on Facebook returns a value for this, so testing for it is redundant.
  5. I've changed the order of the WHERE clause, but that shouldn't matter.


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

Use this queryString. I am not sure but think this will help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号