Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: FQL and SpringSocialFacebook

  1. #1
    Join Date
    Feb 2012
    Posts
    29

    Default FQL and SpringSocialFacebook

    I saw the task https://jira.springsource.org/browse/SOCIALFB-8 targeted at 1.1.0 release, and wondered how it was going.

    I'm about to start diving in to some serious FQL work, and wanted to be sure it going well.
    Might also need to use the multi-query functionality, which makes an even more crazy api.

    Has anybody out there made model classes to hold the data from various tables?
    In particular, for the FQL stream table.

    Thanks in advance,

  2. #2
    Join Date
    Aug 2004
    Posts
    1,099

    Default

    Well, there's an initial bit of FQL work in the latest snapshots. Specifically, FqlOperations give you a method with this signature:

    Code:
    <T> List<T> query(String fql, FqlResultMapper<T> mapper);
    Essentially, you pass in whatever FQL you want along with your implementation of the FqlResultMapper and it will return whatever type the result mapper returns. For example, here's some code from the FqlTemplateTest:

    Code:
    List<StatusObject> results = facebook.fqlOperations().query("SELECT uid, status_id, message, time, source FROM status WHERE uid=me()", new FqlResultMapper<StatusObject>() {
    	public StatusObject mapObject(FqlResult result) {
    		StatusObject status = new StatusObject();
    		status.uid = result.getInteger("uid");
    		status.statusId = result.getString("status_id");
    		status.statusIdLong = result.getLong("status_id");
    		status.message = result.getString("message");
    		status.time = result.getTime("time");
    		status.source = result.getLong("source");
    		return status;
    	}
    });
    It doesn't yet support multi-query (I envision that being a case where you send in a Map<String, String> of queries instead of a simple String), but single queries should work fine. AFAIK, I'm the only one who has tested this, so I welcome you to try it out and let me know what's missing or doesn't work (aside from multi-query, which I already know about).
    Craig Walls
    Spring Social Project Lead

  3. #3
    Join Date
    Feb 2012
    Posts
    29

    Default

    OK, I'll certainly give it a peek.
    As for the mapObject logic, I'm tempted to add in more of the full jackson mapping logic. Many of the tables have complex sub-elements, which will start being more and more cumbersome to create mappers, each time.

    Also thinking of having some cheats for SELECT strings for the basic case of 'return everything', per FQL table.
    The multi-query would also need to be intelligent about partial failures.

    Thanks,
    me

  4. #4
    Join Date
    Aug 2004
    Posts
    1,099

    Default

    Sounds good. I was wondering about nested elements in the return, but on my cursory review of the tables, I couldn't find an example...so I initially assumed a flat structure. Could you give me an example of a table that has more complex sub-elements that would require more detailed JSON-mapping? Not doubting you...just want to see what it looks like.

    If you find opportunity for improvement, I always welcome pull requests!
    Craig Walls
    Spring Social Project Lead

  5. #5
    Join Date
    Feb 2012
    Posts
    29

    Default FQL - stream table complications.

    http://developers.facebook.com/docs/...ce/fql/stream/ has the data for the stream table, which is the wall / home type feed.

    comments array
    An array containing the following information about comments for a post:

    can_remove (bool): Indicates whether users can remove comments
    can_post (bool): Indicates whether users can post comments
    count (int): The total number of comments added to the post
    comment_list (array): A sample of comments made on the post, to get the full list of comments, use the Post Graph API object or query the comment FQL table
    and a few others. The documentation is somewhat thin, so your guess is as good as mine.
    I'll give you more specifics as I walk down that path.

  6. #6
    Join Date
    Feb 2012
    Posts
    29

    Default FqlResult.getTime

    Comment about FqlResult: Most of the calls to getX return null if it's not present in the object map;
    However, getTime will throw an exception.

    Code:
    	
    public Date getTime(String fieldName) {
    	try {
    		long timeInMilliseconds = Long.valueOf(String.valueOf(resultMap.get(fieldName))) * 1000;
    		return resultMap.containsKey(fieldName) ? new Date(timeInMilliseconds) : null;
    	} catch (NumberFormatException e) {
    		throw new FqlException("Field '" + fieldName +"' is not a time.", e);
    	}
    }
    I believe Long.valueOf will be the culprit, as "null" will not parse.
    The API should be consistent in how it treat missing (as opposed for malformed) map entries.

  7. #7
    Join Date
    Aug 2004
    Posts
    1,099

    Default

    Noted and thanks. Will look to correct that soon.
    Craig Walls
    Spring Social Project Lead

  8. #8
    Join Date
    Aug 2004
    Posts
    1,099

    Default

    Rob: Fixed the getTime() to check for null before attempting to convert it to a date. In the master branch now.
    Craig Walls
    Spring Social Project Lead

  9. #9
    Join Date
    Feb 2012
    Posts
    29

    Angry facebook's FQL documentation lies!

    Another thing worth mentioning for anybody else making adapters for FQL - their documentation does not accurately represent the json they return.
    They say things like http://developers.facebook.com/docs/...ce/fql/stream/
    comments array An array containing the following information about comments for a post:
    But it really returns an object with the elements in question as attributes.
    Attempting to parse it with FqlResult as a list will fail.

    Likewise, many other items claiming to return array really return a sub-object.

    Items that claim to return an int will return a value that does not fit in a java int. E.g. source_id
    Items claiming to return an int will also return null, which will fail to parse in FqlResult -
    resultMap.containsKey(fieldName) will return true, but Long.valueOf(String.valueOf(resultMap.get(fieldNam e))) will fail.

    I'm not sure if it is desirable to fill return NULL in that case, or throw exception. I'm very close to using String everywhere I can, instead of the declared FB type.

  10. #10
    Join Date
    Feb 2012
    Posts
    29

    Default FqlResult.getList does not work for array of primitives

    query, modified for simplicity:
    Code:
    SELECT post_id, viewer_id, tagged_ids FROM stream WHERE source_id=100002487294420 AND updated_time>1333363915
    returns
    Code:
    { "data": [ {
          "post_id": "100002487294420_183841518401962",
          "viewer_id": 100003283444808,
          "tagged_ids": [ 100002886616615 ]
        }, {
          "post_id": "100002487294420_261607593932148",
          "viewer_id": 100003283444808,
          "tagged_ids": [ ]
        }...
      ]}
    The problem occurs when trying to use FqlResult.getList to handle it.
    getList assumes the contents of the array are objects, rather than primitives like ints or strings.

    I suppose I need to use getObject() plain?
    Code:
    item.setTagged_ids((List<Long>)result.getObject("tagged_ids"));
    Last edited by Rob Blair; Apr 2nd, 2012 at 07:47 PM. Reason: add example

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •