Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Facebook query not working

I'm not able to get a Facebook query working using the example from Kitchen Sink 1.0. I'm trying to query a wall associated with my company, so I've changed the query using that as the source_ID(replaced here with XXX):

var query = "SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id in (SELECT target_id FROM connection WHERE source_id=XXX) AND is_hidden = 0";

    Titanium.Facebook.query(query, function(r)
    {
        var data = [];
        for (var c=0;c<r.data.length;c++)
        {
            var row = r.data[c];

            var tvRow = Ti.UI.createTableViewRow({
                height:'120',
                selectedBackgroundColor:'#fff',
                backgroundColor:'#fff'
            });

            var imageView = Ti.UI.createImageView({
                url:row.pic_square == null ? './images/IntraHealthWorldsmall' : row.pic_square,
                left:10,
                top:10,
                width:30,
                height:30
            });
            tvRow.add(imageView);

            var userLabel = Ti.UI.createLabel({
                font:{fontSize:16, fontWeight:'bold'},
                left:50,
                top:10,
                right:5,
                height:'auto',
                color:'#576996',
                text:row.actor_id
            });
            tvRow.add(userLabel);

            var statusLabel = Ti.UI.createLabel({
                font:{fontSize:13},
                left:70,
                top:25,
                right:50,
                height:'auto',
                color:'#222',
                text:(!row.status || !row.status.message ? 'No status message' : row.status.message)
            });
            tvRow.add(statusLabel);

            tvRow.uid = row.uid;

            data[c] = tvRow;
        }

This is what I thought would work based on the FQL info for a Live Stream box-like tableview.

— asked March 22nd 2010 by Troy Taylor
  • facebook
  • fql
  • tableview
0 Comments

15 Answers

  • Can you verify the results of JSON.stringify(r) that it has your data or not?

    — answered March 22nd 2010 by Jeff Haynie
    permalink
    0 Comments
  • Really? I've used the exact same query, and is working. What's the error that you get?

    — answered March 23rd 2010 by Manav Uppal
    permalink
    2 Comments
    • Hi i got the same error how can i get my wall post of this following link http://www.facebook.com/pages/A-Discipleship-Journey-ADJ/193480767373875

      — commented July 28th 2011 by Anandhakumar Palanisamy
    • i used the same query but it shows The operation couldn't complete Facebook errDomain error 602

      — commented July 28th 2011 by Anandhakumar Palanisamy
  • Really? I've used the exact same query, and is working. What's the error that you get?

    — answered March 23rd 2010 by Manav Uppal
    permalink
    0 Comments
  • I'm not getting an error - the table view loads without any indication of updates or that it is pulling data. I'd love to see your code if you have it working

    — answered March 23rd 2010 by Troy Taylor
    permalink
    0 Comments
  • Hey Troy,

    That is weird. I've copied and pasted your code into mine and it still works.

    Maybe the problem is with adding the table view to the window?? ( Just a thought. ) What does your debugger say?

    Here's the code snippet that I used, which is working :

    var query = "SELECT post_id, actor_id, target_id, message, updated_time FROM stream ";
        query += "WHERE source_id in (SELECT target_id FROM connection WHERE source_id = XXX)"; 
        query += "AND is_hidden = 0";
    
        Titanium.Facebook.query(query, function(r)
        {
            var data = [];
    
            for (var c=0;c<r.data.length;c++)
            {
                var row = r.data[c];
    
                var tvRow = Titanium.UI.createTableViewRow({
                    height:'120',
                    selectedBackgroundColor:'#555',
                    backgroundColor:'#fff'
                });
    
                var imageView = Titanium.UI.createImageView({
                    url:row.pic_square == null ? 'fbuser.png' : row.pic_square,
                    left:10,
                    width:50,
                    height:50
                });
                tvRow.add(imageView);
    
                //Titanium.API.error('Actor Name : ' + subrow);
    
                var header;
                if (row.target_id == null)
                {
                    header = row.actor_id;
                } else
                {
                    header = row.actor_id + ' -> ' + row.target_id;
                }
                var userLabel = Titanium.UI.createLabel({
                    font:{fontSize:16, fontWeight:'bold'},
                    left:70,
                    top:5,
                    right:5,
                    height:20,
                    color:'#576996',
                    text:header
                });
                tvRow.add(userLabel);
    
                var statusLabel = Titanium.UI.createLabel({
                    font:{fontSize:13},
                    left:70,
                    top:30,
                    right:50,
                    height:'auto',
                    color:'#222',
                    text:(!row.status || !row.status.message ? 'No status message' : row.status.message)
                });
                tvRow.add(statusLabel);
    
                tvRow.uid = row.uid;
    
                data[c] = tvRow;
            }
    

    As you can see, it is exactly the same as yours. Also, what platform are you building on? ( if you don't mind my asking )

    — answered March 23rd 2010 by Manav Uppal
    permalink
    0 Comments
  • This is what I'm getting using your code and my source_id:

    [INFO] Facebook read_stream permission true
    2010-03-24 10:45:03.825 IntraHealth[2663:40b] Connecting to http://api.facebook.com/restserver.php {
    "api_key" = 784c02e296b2b2ff30e04c8f75b932f3;
    "call_id" = 1269441904;
    format = XML;
    method = "facebook.fql.query";
    query = "SELECT post_id, actor_id, target_id, message, updated_time FROM stream WHERE source_id in (SELECT target_id FROM connection WHERE source_id = 232952545017)AND is_hidden = 0";
    "session_key" = "e12bfb0a533d16968a63fee5-1284633359";
    sig = 295fa9b370cd8f1efe47a2cfa4441024;
    ss = 1;
    v = "1.0";
    }
    [DEBUG] in -[WindowViewController viewWillAppear:] (TiWindowProxy.m:46), -> 5045AE0
    [DEBUG] in -[WindowViewController viewDidAppear:] (TiWindowProxy.m:50), -> 5045AE0
    
    — answered March 24th 2010 by Troy Taylor
    permalink
    0 Comments
  • Can you please try inserting the following lines of code in your project. This might help in determining whether the issue is in fetching the data, or displaying the data :

    var row = r.data[c];
    
    Titanium.API.info('Actor ID : ' + row.actor_id);
    Titanium.API.info('Message : ' + row.message);
    
    — answered March 24th 2010 by Manav Uppal
    permalink
    0 Comments
  • I've inserted the two API rows below the var row line and I'm not seeing a data return. Maybe I have the wrong source_ID - I'm using the source_ID that is part of a photo address. Also, the tableview doesn't seem like it's adjusting to the larger row from the default height.

    — answered March 24th 2010 by Troy Taylor
    permalink
    0 Comments
  • Ahh…. I think that's the problem… although, I didn't follow the source_id part… You said you're using the source_id that's part of a photo address?

    The source_id should be the user id that is currently logged in, or the uid of the user for which you need to get the stream. And if that source id does not correspond to any user, then nothing will be returned.

    That's why your API.info isn't showing anything… Have you tried substituting your own uid for the source id? See if you get the data?

    You would do that by setting the source_id to : Titanium.Facebook.getUserId() . This will get the currently logged in user and fetch the stream.

    var query = "SELECT post_id, actor_id, target_id, message, updated_time FROM stream ";
        query += "WHERE source_id in (SELECT target_id FROM connection WHERE source_id = " + Titanium.Facebook.getUserId() + ")"; 
        query += "AND is_hidden = 0";
    

    Or are you trying to do something else and I'm missing the point? :-)

    — answered March 24th 2010 by Manav Uppal
    permalink
    0 Comments
  • That's getting closer. So what I'm trying to do is query my organization's wall, http://www.facebook.com/IntraHealth?ref=ts and return that in a table view. Using that last code, yes, it does pull my status messages, but I'm trying to pull my organization's wall, not mine.

    — answered March 24th 2010 by Troy Taylor
    permalink
    0 Comments
  • Ahhh! Got it… Now I fully understand what you're trying to do ( I think you mentioned that in your first post as well… but it got lost somewhere… :-) )

    Anyways, you'll have to restructure your query a bit. Fire an initial query and get the group id of your organization. ( I'm assuming that you're a member of your organization ). The query will look something like this ( Might need a bit of tweaking, because I wasn't able to test this, as I'm not a member myself, but I'm sure this should point you in the right direction ) :

    var query = "Select gid from group where gid in (select gid from group_member where uid = " + Titanium.Facebook.getUserId() + ") and name = 'IntraHealth International'";
    

    Once you have the gid, you can substitute that in the source_id of your original query, and that should get you your org's wall…

    Hope this helps. :-)

    — answered March 24th 2010 by Manav Uppal
    permalink
    0 Comments
  • Hi Troy,

    Just curious…. Did it work?

    — answered March 31st 2010 by Manav Uppal
    permalink
    0 Comments
  • Hi Troy,

    Did it finally work? I have the same problem. The table view loads without any indication of updates or that it is pulling data. I have the Group ID (it's a public facebook group)

    Thanks

    Marc

    — answered August 3rd 2010 by Marc Constanti
    permalink
    0 Comments
  • This is what I get when I do JSON.stringify(r);
    I'm trying to pull a FB Page wall with the number in source_id, is that correct?

    2010-12-01 20:41:56.613 DISTRICT[28152:207] Connecting to http://api.facebook.com/restserver.php {
    "api_key" = 7ca1ebfca571a87a9b8b28999b54f895;
    "call_id" = 1291254117;
    format = XML;
    method = "facebook.fql.query";
    query = "SELECT post_id, actor_id, target_id, message, updated_time FROM stream WHERE source_id in (SELECT target_id FROM connection WHERE source_id = 54095145958)AND is_hidden = 0 LIMIT 30";
    "session_key" = "2.0EbppK8yhBFNvyeuUmoXfA__.3600.1291258800-1508490022";
    sig = 8141c2ecef130b7c5751fe145a6aeca1;
    ss = 1;
    v = "1.0";
    }
    [INFO] {"type":"query","data":[],"source":{},"success":true}
    
    — answered December 1st 2010 by Logan Best
    permalink
    0 Comments
  • Hi i got the same error while doing this query for the following link http://www.facebook.com/pages/A-Discipleship-Journey-ADJ/193480767373875.
    here what i am doing, i want to display the wall post of this from table view
    so what is my mistake. i am new to Titanium can any one help me to light up my knowledge

    — answered July 28th 2011 by Anandhakumar Palanisamy
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.