2011-07-18 55 views
0

[注意:前兩個答案,包括我寫的一個,還沒有處理「可選的」fql.multiquery問題。]使用facebook fql,我怎麼找到學校在哪裏?

當我使用Facebook的fql時,我可以得到一份學校列表我參加過,或者有朋友參加過。具體來說,我可以獲得學校的名稱,它是Facebook的ID。但是,我不知道如何查詢有關這些學校的更深層次的信息。

具體來說,我想知道學校的位置。但是,我不知道Facebook圖形實體(或任何其他)的學校ID是其中的一部分。

如何從facebook上找到這些學校所在的位置?

可選:如果這可以在首先返回學校列表的相同多查詢中完成(這將是針對用戶表對我的ID和針對用戶表的另一個查詢的查詢爲我的朋友的一些ID)。

下面是上述段落中提到的可選部分的擴展版本(注意,我試圖將其作爲一個單獨的問題加入,但是當我將這些說明性數據更相關時,我發現它已經悄無聲息地消失了。我假設我絆了一堆堆棧溢出的功能,旨在清除彼此過於相似的問題,所以我們只是說這是我的意思,在上面段落中的說明)

使用Facebook的JavaScript sdk,這失敗,默默地:

FB.login(function(response){ 
    disp('loginResponse', response); 
    var userQuery= FB.Data.query(
    'select uid,name,education from user where uid= {0}' 
     , response.session.uid); 

    var friendlist = FB.Data.query(
    'select uid2 from friend where uid1 = {0} order by rand() limit 10' 
    , response.session.uid); 

    var friends = FB.Data.query(
    'select uid,name,education from user where uid in (select uid2 from {0})' 
    , friendlist); 

    var friendSchools= FB.Data.query(
    'select page_id,name,location from page where page_id in (select education.school.id from {0})' 
    , friends); 

    self.queries= [userQuery, friendlist, friends, friendSchools]; 
    FB.Data.waitOn(queries 
     , function() {alert(1)}); 
    }) 

如果我刪除朋友從查詢陣列學校元素,它工作得很好,和朋友不妨通過這樣一個對象表示:

{ 
    uid: '...', 
    name: '...', 
    education: 
    [ 
     { 
     school: 
      { 
      id: '115920001751600', 
      name: 'Burlington High School' 
      }, 
     year: 
      { 
      id: '138792749476094', 
      name: '1978' 
      }, 
     type: 'High School' 
     }, 
     { 
     school: 
      { 
      id: '20697868961', 
      name: 'Boston University' 
      }, 
     degree: 
      { 
      id: '188387604516411', 
      name: 'BS' 
      }, 
     year: 
      { 
      id: '103823546338323', 
      name: '1982' 
      }, 
     type: 'College' 
     } 
    ] 
} 

那麼,我該如何重組在friendSchools查詢的WHERE子句,使得查詢可以執行?

換句話說,我該如何使用fql.multiquery來查找有關在多查詢中其他地方返回的學校(或其他類似實體)的信息?

回答

1

我建議使用批量請求(更多信息請點擊:https://developers.facebook.com/docs/reference/api/batch/)根據您已有的學校ID查詢圖表。學校的位置可以通過它返回的默認基本信息來檢索(下面的例子)。

{ 
    "id": "6192688417", 
    "name": "Stanford University", 
    "picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/41571_6192688417_2310209_s.jpg", 
    "link": "https://www.facebook.com/stanford", 
    "likes": 203153, 
    "category": "Education", 
    "website": "http://www.stanford.edu", 
    "username": "stanford", 
    "founded": "1891", 
    "location": { 
     "street": "450 Serra Mall", 
     "city": "Stanford", 
     "state": "CA", 
     "country": "United States", 
     "zip": "94305", 
     "latitude": 37.42895, 
     "longitude": -122.1697 
    }, 
    "public_transit": "http://transportation.stanford.edu", 
    "general_info": "Located between San Francisco and San Jose in the heart of Silicon Valley, Stanford University is recognized as one of the world's leading research and teaching institutions.\n\nLeland and Jane Stanford founded the University to \"promote the public welfare by exercising an influence on behalf of humanity and civilization.\" Stanford opened its doors in 1891, and more than a century later, it remains dedicated to finding solutions to the great challenges of the day and to preparing our students for leadership in today's complex world.", 
    "checkins": 9938 
} 
+2

值得一提的是,這信息未經Facebook驗證或輸入,因此您檢索的內容可能並不總是準確或完整。 –

+0

好吧,我看到了 - id本身就是一個節點本身,沒有進一步的資格要求。也就是說,批處理api對於我的目的看起來很醜陋(你在<腳本標記中使用jsonp,但批處理需要一個表單),所以我將不得不尋找替代方法(儘管試驗我是否可以批處理如果使用GET,使用GET可能就足夠了。) – rdm

0

而且,它看起來像讓fql工作我想查詢頁表。例如:

select name,location from page where page_id = 87873693141 

(儘管如此,我仍然試圖找出如何提取列表我的教育的學校IDS成多查詢的WHERE子句。)

相關問題