FQL query to get the Immediate family (name, birthday and relationship)

試著忘記壹切 提交于 2019-12-12 05:26:27

问题


I trying to get my immediate family data from facebook using FQL. I run this statement:

SELECT first_name, middle_name, last_name, birthday_date 
from user 
where uid IN (SELECT uid 
              FROM family 
              WHERE profile_id = me() 
              and (relationship = 'brother' 
                   or relationship = 'sister' 
                   or relationship = 'father' 
                   or relationship = 'mother' 
                   or relationship = 'son' 
                   or relationship = 'daughter' 
                   or relationship = 'wife' 
                   or relationship = 'husband'))

But I want to have also the relatioship in the data. It gives me only first_name, middle_name, last_name, birthday_date


回答1:


You have to do a to get this data, you need to do an FQL multi-query:

{"my_family": "SELECT uid, relationship FROM family WHERE profile_id = me() AND
       (relationship = 'brother' OR ...)".
"family_details": "SELECT first_name, middle_name, last_name, birthday_date FROM
       user WHERE uid IN (SELECT uid FROM #my_family)"}

You'll need to join the two result objects together on uid in your script.




回答2:


Do you need to use FQL? There is now a nested field Graph API syntax that gets you exactly what you need in one go:

https://graph.facebook.com/me?fields=id,name,family.fields(first_name,middle_name,last_name,birthday)

The result is then a nested JSON object with the relationship field as you require - something like:

{
  "id": "738229837", 
  "name": "James Pearce", 
  "family": {
    "data": [
      {
        "first_name": "Bob", 
        "last_name": "Pearce", 
        "birthday": "09/21/1965", 
        "id": "12345", 
        "relationship": "cousin"
      }, 
      {
        "first_name": "Clara", 
        "last_name": "Pearce", 
        "birthday": "12/08", 
        "id": "67890", 
        "relationship": "mother"
      }
      ...
    ], 
    "paging": {
      "next": "https://graph.facebook.com/..."
    }
  }
}

Hope that helps. Have fun.



来源:https://stackoverflow.com/questions/12965159/fql-query-to-get-the-immediate-family-name-birthday-and-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!