message - RestFB: Exception: Unable to convert Facebook response JSON to a list of java.lang.String instances -
message - RestFB: Exception: Unable to convert Facebook response JSON to a list of java.lang.String instances -
i have desktop application reads facebook messages (unified_message in fql terms), left on facebook page other users. problem is: when user writes message, include link, facebook automatically attaches object message. , attachment causes exception in restfb lib. unfortunately, page access token not help, because have logged in me in facebook in order utilize it. scenario simple, seek leave message on page “www.wheather.com - cool site”. i’ve tried restfb 1.6.9 , 1.6.11 – same result both. sorry formatting. couldn't in other way :(
here stack 1.6.11:
com.restfb.exception.facebookjsonmappingexception: unable convert facebook response json list of java.lang.string instances. offending json {"38d79791ef0dac6f0b645a87f4d152d7":{"icon":"https://fbstatic-a.akamaihd.net/rsrc.php/v2/yd/r/as8ecmyrys0.gif","fb_object_type":"","tagged_ids":[],"description":"the weather channel , weather.com provide national , local weather forecast cities, weather radar, study , hurricane coverage.","name":"national , local weather forecast, hurricane, radar , report","fb_object_id":"","caption":"www.weather.com","properties":[],"media":[],"href":"http://www.weather.com/"}} @ com.restfb.defaultjsonmapper.tojavalist(defaultjsonmapper.java:171) @ com.restfb.defaultjsonmapper.tojavatype(defaultjsonmapper.java:653) @ com.restfb.defaultjsonmapper.tojavaobject(defaultjsonmapper.java:290) @ com.restfb.defaultjsonmapper.tojavalist(defaultjsonmapper.java:181) @ com.restfb.defaultjsonmapper.tojavatype(defaultjsonmapper.java:653) @ com.restfb.defaultjsonmapper.tojavaobject(defaultjsonmapper.java:290) @ myprogram.mydefaultfacebokclient.executemultiquery(mydefaultfacebokclient.java:62) caused by: com.restfb.json.jsonexception: jsonobject["data"] not found. @ com.restfb.json.jsonobject.get(jsonobject.java:525) @ com.restfb.defaultjsonmapper.tojavalist(defaultjsonmapper.java:155) ... 17 more
here stack 1.6.9:
com.restfb.exception.facebookjsonmappingexception: unable convert facebook response json list of java.lang.string instances. offending json {"38d79791ef0dac6f0b645a87f4d152d7":{"icon":"https://fbstatic-a.akamaihd.net/rsrc.php/v2/yd/r/as8ecmyrys0.gif","fb_object_type":"","tagged_ids":[],"description":"the weather channel , weather.com provide national , local weather forecast cities, weather radar, study , hurricane coverage.","name":"national , local weather forecast, hurricane, radar , report","fb_object_id":"","caption":"www.weather.com","properties":[],"media":[],"href":"http://www.weather.com/"}} @ com.restfb.defaultjsonmapper.tojavalist(defaultjsonmapper.java:167) @ com.restfb.defaultjsonmapper.tojavatype(defaultjsonmapper.java:602) @ com.restfb.defaultjsonmapper.tojavaobject(defaultjsonmapper.java:279) @ com.restfb.defaultjsonmapper.tojavalist(defaultjsonmapper.java:177) @ com.restfb.defaultjsonmapper.tojavatype(defaultjsonmapper.java:602) @ com.restfb.defaultjsonmapper.tojavaobject(defaultjsonmapper.java:279) @ myprogram.mydefaultfacebokclient.executemultiquery(mydefaultfacebokclient.java:62) . . . caused by: com.restfb.json.jsonexception: jsonobject["data"] not found. @ com.restfb.json.jsonobject.get(jsonobject.java:525) @ com.restfb.defaultjsonmapper.tojavalist(defaultjsonmapper.java:151) ... 17 more
here fql request:
{ "users":"select uid,first_name,middle_name,last_name,name,pic_small,pic_big,profile_update_time,timezone,religion,birthday,birthday_date,sex,hometown_location,relationship_status,political,current_location,about_me,notes_count,wall_count,status,locale,profile_url,verified,profile_blurb,username,is_blocked,email,friend_count,languages user uid in (select sender #messages)" ,"msg":"select message_id unified_message thread_id='t_id.238275946308607' , timestamp > '1360112817564' , sender.user_id != '507447822604742' limit 100" ,"messages":"select message_id,thread_id,subject,body,unread,action_id,timestamp,tags,sender,recipients,object_sender,html_body,attachments,shares,share_map unified_message message_id in (select message_id #msg) , timestamp > '1360112817564' , timestamp <= '1360117314920' limit 100" }
here reply facebook explorer on request above:
{ "data": [ { "name": "msg", "fql_result_set": [ { "message_id": "m_mid.1360112949050:d17ca4ed7fc6236a75" } ] }, { "name": "messages", "fql_result_set": [ { "message_id": "m_mid.1360112949050:d17ca4ed7fc6236a75", "thread_id": "t_id.238275946308607", "subject": null, "body": "have on http://www.weather.com 1", "unread": true, "action_id": "1360112949128000000", "timestamp": "1360112949058", "tags": [ "inbox", "source:web" ], "sender": { "name": "adam client", "email": "100004967623158@facebook.com", "user_id": "100004967623158" }, "recipients": [ { "name": "mb aerospace corp.", "email": "507447822604742@facebook.com", "user_id": "507447822604742" }, { "name": "adam client", "email": "100004967623158@facebook.com", "user_id": "100004967623158" } ], "object_sender": null, "html_body": "have on http://www.weather.com 1", "attachments": [ ], "shares": [ "38d79791ef0dac6f0b645a87f4d152d7" ], "share_map": { "38d79791ef0dac6f0b645a87f4d152d7": { "media": [ ], "name": "national , local weather forecast, hurricane, radar , report", "href": "http://www.weather.com/", "caption": "www.weather.com", "description": "the weather channel , weather.com provide national , local weather forecast cities, weather radar, study , hurricane coverage.", "properties": [ ], "fb_object_type": "", "fb_object_id": "", "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yd/r/as8ecmyrys0.gif", "tagged_ids": [ ] } } } ] }, { "name": "users", "fql_result_set": [ { "uid": 100004967623158, "first_name": "adam", "middle_name": "", "last_name": "client", "name": "adam client", "pic_small": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/371585_100004967623158_2019810380_t.jpg", "pic_big": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/371585_100004967623158_2019810380_n.jpg", "profile_update_time": 1360108999, "timezone": null, "religion": null, "birthday": null, "birthday_date": null, "sex": "male", "hometown_location": null, "relationship_status": null, "political": null, "current_location": null, "about_me": null, "notes_count": null, "wall_count": null, "status": null, "locale": "en_us", "profile_url": "https://www.facebook.com/adam.client.5", "verified": null, "profile_blurb": null, "username": "adam.client.5", "is_blocked": false, "email": null, "friend_count": 1, "languages": [ ] } ] } ] }
and lastly one. utilize redefined facebookclient. source taken here, stackoverflow.com. don’t remember why defaultfacebookclient not correctly map results facebook (attachments messages).
public class mydefaultfacebokclient extends defaultfacebookclient { @override public <t> t executemultiquery (map<string, string> queries, class<t> objecttype, parameter... parameters) { verifyparameterpresence("objecttype", objecttype); (parameter parameter : parameters) if (query_param_name.equals(parameter.name)) throw new illegalargumentexception("you cannot specify '" + query_param_name + "' url parameter - " + "restfb populate " + "the queries passed method."); seek { list<jsonobject> jsonobjects = jsonmapper.tojavalist(makerequest("fql", false, false, null, parameterswithadditionalparameter(parameter.with("q", queriestojson(queries)), parameters)), jsonobject.class); jsonobject normalizedjson = new jsonobject(); (int = 0; < jsonobjects.size(); i++) { jsonobject jsonobject = jsonobjects.get(i); // empty result sets, facebook homecoming empty object instead of // empty list. hack around here. jsonarray resultsarray = jsonobject.get("fql_result_set") instanceof jsonarray ? jsonobject.getjsonarray("fql_result_set") : new jsonarray(); normalizedjson.put(jsonobject.getstring("name"), resultsarray); } homecoming objecttype.equals(jsonobject.class) ? (t) normalizedjson : jsonmapper.tojavaobject(normalizedjson.tostring(), objecttype); } grab (jsonexception e) { throw new facebookjsonmappingexception("unable process fql.multiquery json response", e); } } }
any ideas appreciated.
i'm author of restfb. maybe pull latest github, run "ant dist" create 1.6.12 jar, , seek calling new facebookclient.executefqlmultiquery method instead of facebookclient.executemultiquery().
the new graph api fql endpoint little different old 1 , new executefqlmultiquery() method should prepare problem you're seeing. allow me know if not, or if you're having problems mapping result type correctly.
here's quick illustration of how might utilize new method, copied https://groups.google.com/forum/?fromgroups=#!topic/restfb/yjcxsquiiee:
static void test() throws exception { facebookclient facebookclient = new defaultfacebookclient("xxx"); final string threadsfql = "select action_id, archived, can_reply, folder, former_participants, has_attachments, " + "is_subscribed, last_visible_add_action_id, name, num_messages, num_unread, object_participants, " + "participants, senders, single_recipient, snippet, snippet_sender, snippet_message_has_attachment, " + "subject, tags, thread_id, thread_participants, timestamp, unread " + "from unified_thread folder='inbox' , has_attachments='1'"; final string messagesfql = "select message_id, thread_id, subject, body, unread, action_id, timestamp, tags, sender, recipients, " + "object_sender, html_body, attachments, attachment_map, shares, share_map " + "from unified_message thread_id in (select thread_id #threads) limit 2"; complexmappingresults results = facebookclient.executefqlmultiquery(new hashmap<string, string>() { { put("threads", threadsfql); put("messages", messagesfql); } }, complexmappingresults.class); out.println(results); } public static class complexmappingresults { @facebook private list<thread> threads; @facebook private list<message> messages; @override public string tostring() { homecoming reflectionutils.tostring(this); } public list<thread> getthreads() { homecoming threads; } public list<message> getmessages() { homecoming messages; } }
json message
Comments
Post a Comment