i'm getting json raw data , i'm parsing fine in main class.but don't have idea how write pojo values json raw data i'm parsing.this class gets raw json , parses needed fields want write pojo fields.
public class facebookparser { public static void main(string[] args) throws facebookexception, jsonexception, ioexception { // generate facebook instance. facebook facebook = new facebookfactory().getinstance(); // use default values oauth app id. facebook.setoauthappid("appid", "app-sec-id"); accesstoken accesstokenstring = facebook.getoauthappaccesstoken(); facebook.setoauthaccesstoken(accesstokenstring); stringbuilder sb = new stringbuilder(); string z=""; string m ="anushkashetty/?fields=posts.limit(2).since(2015).until(now){id,message,name,type,picture,link,caption,description,icon,application,shares,updated_time,source,comments.limit(500).summary(true){comment_count,message,can_remove,id,created_time,can_like,like_count,comments{comment_count,comments{comment_count}}},place,object_id,privacy,status_type,created_time,story,parent_id,story_tags,full_picture,likes.limit(9999).summary(true){id,name,username}},id,hometown,website,about,location,birthday,name,tagged{message_tags},category,category_list,talking_about_count,likes"; //rawapiresponse res = facebook.callgetapi(n);//"me/friends" rawapiresponse res1 = facebook.callgetapi(m);//"me/friends" jsonobject mainobject= res1.asjsonobject(); system.out.println(mainobject); //print mainjson object //page details in mainjson string id=mainobject.getstring("id"); string birthday=mainobject.getstring("birthday"); string category=mainobject.getstring("category"); string website=mainobject.getstring("website"); string page_likes=mainobject.getstring("likes"); string name=mainobject.getstring("name"); string about=mainobject.getstring("about"); string talking_about_count=mainobject.getstring("talking_about_count"); /* system.out.println("id: "+id); system.out.println("birthday: "+birthday); system.out.println("category: "+category); system.out.println("website: "+website); system.out.println("website: "+page_likes); system.out.println("name: "+name); system.out.println("about: "+about); system.out.println("talking_about_count: "+talking_about_count);*/ //location details of page jsonobject location=mainobject.getjsonobject("location"); string page_country=location.getstring("country"); string page_city=location.getstring("city"); /* system.out.println("country :"+page_country); system.out.println("page_city :"+page_city); */ jsonobject posts = mainobject.getjsonobject("posts"); jsonarray data = posts.getjsonarray("data"); for(int i=0;i<data.length();i++){ jsonobject dataobjs = data.getjsonobject(i); string full_picture=dataobjs.getstring("full_picture"); system.out.println("full_picture "+full_picture); string link=dataobjs.getstring("link"); system.out.println("link "+link); string type=dataobjs.getstring("type"); system.out.println("type "+type); string updated_time=dataobjs.getstring("updated_time"); system.out.println("updated_time "+updated_time); string postid=dataobjs.getstring("id"); system.out.println("post_id "+postid); string postmessage=dataobjs.getstring("message"); system.out.println("post_message "+postmessage); string postpicture=dataobjs.getstring("picture"); system.out.println("post_picture "+postpicture); try{ string poststory=dataobjs.getstring("story"); // system.out.println("story "+poststory); string postsource=dataobjs.getstring("source"); arraylist<string> elements = new arraylist<>(); system.out.println("post_source "+postsource); system.out.println("**"+elements); string postdescription=dataobjs.getstring("description"); system.out.println("postdescription "+postdescription); string statustype=dataobjs.getstring("status_type"); system.out.println("status_type "+statustype); string postname=dataobjs.getstring("name"); system.out.println("postname "+postname); string postcreatedat=dataobjs.getstring("created_time"); system.out.println("postcreatedat "+postcreatedat); string postparentid=dataobjs.getstring("parent_id"); system.out.println("parent_id "+postparentid); }catch(exception e ){system.err.println();} //privacy object jsonobject privacy=dataobjs.getjsonobject("privacy"); for(int pri=0;pri<privacy.length();pri++){ string friends=privacy.getstring("friends"); string allow=privacy.getstring("allow"); string deny=privacy.getstring("deny"); string privacydescription=privacy.getstring("description"); string value=privacy.getstring("value"); } //story_tags try{ jsonarray storytags=dataobjs.getjsonarray("story_tags"); for(int story=0;story<storytags.length();story++) { jsonobject storydata=storytags.getjsonobject(story); string storyid=storydata.getstring("id"); try{ string storyname=storydata.getstring("name"); system.out.println(" same same "+storyname); }catch(exception e ){string storyname="dummie";} string storylength=storydata.getstring("length"); string storyoffset=storydata.getstring("offset"); string storytype=storydata.getstring("type"); system.out.println("same same "+id); } }catch(exception e ){ system.err.println();} }//main_close }//class_close
Comments
Post a Comment