fql join; can i join two tables with FQL?

你离开我真会死。 提交于 2019-12-18 17:07:46

问题


I have the following FQL I want to join with user table to add name field! How can I do that?After I test making normal left join I got error message (601 join not possible with FQL). How can I join and add name field????

<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
<a href="#" onclick="getPhotos();return false;">Get Photos</a>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({ appId: 'yourAppID', status: true, cookie: true, xfbml : true });

  function getPhotos() {  
    FB.login(function(response) {
      if (response.session && response.perms) {
        var oneWeekAgo = Math.round((new Date().setDate(new Date().getDate()-7)) / 1000);
        FB.api(
          {
            method: 'fql.query',
            query: 'SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified FROM photo WHERE aid IN (SELECT aid FROM album WHERE owner IN (SELECT uid2 FROM friend WHERE uid1=me())) AND created > ' + oneWeekAgo + ' ORDER BY created DESC LIMIT 20'
          },
          function(response) {
            alert('Photos: ' + JSON.stringify(response));
          }
        );
      }
    } , {perms:'friends_photos'}); 
}
</script>
</body>
</html>

回答1:


Do something like this:

FB.api({
    method: 'fql.multiquery',
    queries: {
        'query1': 'SELECT uid2 FROM friend WHERE uid1 = me()',
        'query2': 'SELECT vid, owner, title, description FROM video WHERE owner IN (SELECT uid2 FROM #query1)'
    }
},
function(response) {
    // response should have 2 objects in it, both containing an fql_result_set 
    // array with the data and the name you entered for the query (i.e. 'query1')
    alert('Photos: ' + JSON.stringify(response));
});



回答2:


you need to run a nested query like

https://api.facebook.com/method/fql.query?query=SELECT uid,pic_square, first_name, last_name from user where uid IN (SELECT uid FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())AND page_id = PAGE_ID)&access_token=YOUR_ACCESS_TOKEN

i need the my friend name, pic from a page whoever liked that page.so run a nested query and it worked form me

Check this link https://developers.facebook.com/docs/reference/fql/

Facebook have exposed their database. Hope it helps you



来源:https://stackoverflow.com/questions/6553962/fql-join-can-i-join-two-tables-with-fql

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