LinkedIn Connections List code is Required for android application -


i new in android , working on project shows different friend list of different social network. here @ stage fail linkedin connections list , have searched rest of internet couldn't find way. . .

if know code please me. . . in advance. .

cheer!

sample code here bellow. . .

final linkedinoauthservice oauthservice = linkedinoauthservicefactory         .getinstance().createlinkedinoauthservice(                 config.linkedin_consumer_key,config.linkedin_consumer_secret, config.scopeparams); final linkedinapiclientfactory factory = linkedinapiclientfactory         .newinstance(config.linkedin_consumer_key,                 config.linkedin_consumer_secret); linkedinrequesttoken litoken; linkedinapiclient client; linkedinaccesstoken accesstoken = null;  @targetapi(build.version_codes.gingerbread) @suppresslint("newapi") @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      if( build.version.sdk_int >= 9){         strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build();         strictmode.setthreadpolicy(policy);      }     share = (button) findviewbyid(r.id.share);     name = (textview) findviewbyid(r.id.name);     et = (edittext) findviewbyid(r.id.et_share);     login = (button) findviewbyid(r.id.login);     photo = (imageview) findviewbyid(r.id.photo);      login.setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {             linkedinlogin();         }     });      // share on linkedin     share.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             string share = et.gettext().tostring();             if (null != share && !share.equalsignorecase("")) {                 oauthconsumer consumer = new commonshttpoauthconsumer(config.linkedin_consumer_key, config.linkedin_consumer_secret);                 consumer.settokenwithsecret(accesstoken.gettoken(), accesstoken.gettokensecret());                 defaulthttpclient httpclient = new defaulthttpclient();                 httppost post = new httppost("https://api.linkedin.com/v1/people/~/shares");                 try {                     consumer.sign(post);                 } catch (oauthmessagesignerexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (oauthexpectationfailedexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (oauthcommunicationexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } // here need consumer sign in post share                 post.setheader("content-type", "text/xml");                 string myentity = "<share><comment>"+ share +"</comment><visibility><code>anyone</code></visibility></share>";                 try {                     post.setentity(new stringentity(myentity));                     org.apache.http.httpresponse response = httpclient.execute(post);                     toast.maketext(linkedinsampleactivity.this,                             "shared sucessfully", toast.length_short).show();                 } catch (unsupportedencodingexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (clientprotocolexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }             }else {                 toast.maketext(linkedinsampleactivity.this,                         "please enter text share",                         toast.length_short).show();             }              /*string share = et.gettext().tostring();             if (null != share && !share.equalsignorecase("")) {                 client = factory.createlinkedinapiclient(accesstoken);                 client.postnetworkupdate(share);                 et.settext("");                 toast.maketext(linkedinsampleactivity.this,                         "shared sucessfully", toast.length_short).show();             } else {                 toast.maketext(linkedinsampleactivity.this,                         "please enter text share",                         toast.length_short).show();             }*/         }     }); }  private void linkedinlogin() {     progressdialog progressdialog = new progressdialog(             linkedinsampleactivity.this);      linkedindialog d = new linkedindialog(linkedinsampleactivity.this,             progressdialog);     d.show();      // set call listener oauth_verifier value     d.setverifierlistener(new onverifylistener() {         @override         public void onverify(string verifier) {             try {                 log.i("linkedinsample", "verifier: " + verifier);                  accesstoken = linkedindialog.oauthservice                         .getoauthaccesstoken(linkedindialog.litoken,                                 verifier);                 linkedindialog.factory.createlinkedinapiclient(accesstoken);                 client = factory.createlinkedinapiclient(accesstoken);                 // client.postnetworkupdate("testing mukesh!!! linkedin wall post android app");                 log.i("linkedinsample",                         "ln_access_token: " + accesstoken.gettoken());                 log.i("linkedinsample",                         "ln_access_token: " + accesstoken.gettokensecret());                 person p = client.getprofileforcurrentuser();                 name.settext("welcome " + p.getfirstname() + " "                         + p.getlastname());                 name.setvisibility(0);                 login.setvisibility(4);                 share.setvisibility(0);                 et.setvisibility(0);              } catch (exception e) {                 log.i("linkedinsample", "error verifier");                 e.printstacktrace();             }         }     });      // set progress dialog     progressdialog.setmessage("loading...");     progressdialog.setcancelable(true);     progressdialog.show(); } 

}

try user-connections

        public class linkcon_main extends baseactivitylistview {      final linkedinoauthservice oauthservice = linkedinoauthservicefactory             .getinstance().createlinkedinoauthservice(config.consumer_key,                     config.consumer_secret);     final linkedinapiclientfactory factory = linkedinapiclientfactory             .newinstance(config.consumer_key, config.consumer_secret);       progressdialog mprograss;     string name;     view experiencepage;      textview prof_name, prof_headline, prof_location, prof_industry;      string prof_name, prof_headline, prof_location, prof_industry, prof_summary, prof_experience,prof_education,prof_languages,prof_skills, prof_interests,prof_birthdate,prof_contatct,prof_email;     string con_name, con_headline, con_location,con_industry, con_summary,con_experience,con_education,con_languages,con_skills,con_interets,con_birthdate,con_phone;     connections con_email;     string pic_url,con_pic_url;     string startdate, enddate;     string item;     string dty;     string dtm;     string dtd;       imageview person_pic, con_pic;      map<searchparameter, string> searchparameters;      listview connections_list;     arraylist<person> itemslist;        @suppresswarnings({ "rawtypes" })     iterator localiterator;      person mylist;     relativelayout  layout_persondetils,layout_con_profile;     linkedinapiclient client;     person person;     connections connections;     imageloader imageloader;     displayimageoptions options;     linkconapp mylinkcon;     layoutinflater inflater;     string[] months= {"jan", "feb", "march", "april", "may","june", "july", "august","sep", "oct", "nov", "dec"};     stringbuilder localstringbuilder;      @override     @suppresslint("newapi")     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          mylinkcon=new linkconapp();         prof_name=(textview)findviewbyid(r.id.user_name);         prof_headline=(textview)findviewbyid(r.id.user_headline);         prof_location=(textview)findviewbyid(r.id.user_location);         prof_industry=(textview)findviewbyid(r.id.user_industry);         person_pic=(imageview)findviewbyid(r.id.profile_pic);         layout_persondetils=(relativelayout)findviewbyid(r.id.layout_profiledetils);         layout_con_profile=(relativelayout)findviewbyid(r.id.layout_con_profile);          layout_persondetils.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 userpersons();             }         });          mprograss=new progressdialog(linkcon_main.this);         inflater=(layoutinflater)getsystemservice(context.layout_inflater_service);          // imageloader options         options = new displayimageoptions.builder()         .showimageonloading(r.drawable.ic_launcher)         .showimageforemptyuri(r.drawable.photo)         .showimageonfail(r.drawable.ic_launcher).cacheinmemory(true)         .cacheondisc(true).considerexifparams(true).build();          imageloader = imageloader.getinstance();         imageloader.init(imageloaderconfiguration.createdefault(this));          connections_list=(listview)findviewbyid(r.id.connectionslist);          itemslist = new arraylist<person>();          if( build.version.sdk_int >= 9){             strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build();             strictmode.setthreadpolicy(policy);          }           final sharedpreferences pref = getsharedpreferences(config.oauth_pref,                 mode_private);         final string token = pref.getstring(config.pref_token, null);         final string tokensecret = pref.getstring(config.pref_tokensecret, null);          if (token == null || tokensecret == null) {             startautheniticate();         } else {             showcurrentuser(new linkedinaccesstoken(token, tokensecret));         }       }      void startautheniticate() {         mprograss.setmessage("loading...");         mprograss.setcancelable(true);         mprograss.show();         new asynctask<void, void, linkedinrequesttoken>() {              @override             protected linkedinrequesttoken doinbackground(void... params) {                 return oauthservice.getoauthrequesttoken(config.oauth_callback_url);             }              @override             protected void onpostexecute(linkedinrequesttoken litoken) {                 final string uri = litoken.getauthorizationurl();                 getsharedpreferences(config.oauth_pref, mode_private)                 .edit()                 .putstring(config.pref_reqtokensecret,                         litoken.gettokensecret()).commit();                 intent = new intent(intent.action_view, uri.parse(uri));                 startactivity(i);             }          }.execute();         mprograss.dismiss();     }       void finishauthenticate(final uri uri) {         if (uri != null && uri.getscheme().equals(config.oauth_callback_scheme)) {             final string problem = uri.getqueryparameter(config.oauth_query_problem);             if (problem == null) {                  new asynctask<void, void, linkedinaccesstoken>() {                      @override                     protected linkedinaccesstoken doinbackground(void... params) {                         final sharedpreferences pref = getsharedpreferences(                                 config.oauth_pref, mode_private);                         final linkedinaccesstoken accesstoken = oauthservice                                 .getoauthaccesstoken(                                         new linkedinrequesttoken(                                                 uri.getqueryparameter(config.oauth_query_token),                                                 pref.getstring(                                                         config.pref_reqtokensecret,                                                         null)),                                                         uri.getqueryparameter(config.oauth_query_verifier));                         pref.edit()                         .putstring(config.pref_token, accesstoken.gettoken())                         .putstring(config.pref_tokensecret,                                 accesstoken.gettokensecret())                                 .remove(config.pref_reqtokensecret).commit();                         return accesstoken;                     }                      @override                     protected void onpostexecute(linkedinaccesstoken accesstoken) {                         mprograss.dismiss();                         showcurrentuser(accesstoken);                     }                 }.execute();              } else {                 toast.maketext(this,                         "appliaction down due oauth problem: " + problem,                         toast.length_long).show();                 finish();             }          }     }      void cleartokens() {         getsharedpreferences(config.oauth_pref, mode_private).edit()         .remove(config.pref_token).remove(config.pref_tokensecret)         .remove(config.pref_reqtokensecret).commit();     }       void showcurrentuser(final linkedinaccesstoken accesstoken) {          client = factory.createlinkedinapiclient(accesstoken);         mprograss.setmessage("loading..");         mprograss.show();         new asynctask<void, void, object>() {               @override             protected object doinbackground(void... params) {                 try {                      final person user_profile = client.getprofileforcurrentuser(enumset.of(profilefield.id));                      person = client.getprofilebyid(user_profile.getid(), enumset.of(                             profilefield.first_name,                             profilefield.last_name,                             profilefield.picture_url,                             profilefield.industry,                             profilefield.main_address,                             profilefield.headline,                             profilefield.summary,                             profilefield.positions,                             profilefield.educations,                             profilefield.languages,                             profilefield.skills,                             profilefield.interests,                             profilefield.phone_numbers,                             profilefield.email_address,                             profilefield.date_of_birth,                             profilefield.public_profile_url));                       prof_name       = person.getfirstname() + " "   + person.getlastname();                     prof_headline   = person.getheadline();                     prof_location   = person.getmainaddress();                     prof_industry   = person.getindustry();                       return person;                  } catch (linkedinapiclientexception ex) {                     return ex;                 }             }              @override             protected void onpostexecute(object result) {                 if (result instanceof exception) {                     //result exception :)                      final exception ex = (exception) result;                     cleartokens();                     toast.maketext(                             linkcon_main.this,                             "appliaction down due linkedinapiclientexception: "                                     + ex.getmessage()                                     + " authokens cleared - try run application again.",                                     toast.length_long).show();                     finish();                 } else if (result instanceof person) {                      final person person = (person) result;                      prof_name.settext( person.getfirstname() + " "  + person.getlastname());                     prof_headline.settext(person.getheadline());                     prof_location.settext(person.getmainaddress());                     prof_industry.settext(person.getindustry());                      prof_name.setvisibility(0);                     prof_headline.setvisibility(0);                     prof_location.setvisibility(0);                     prof_industry.setvisibility(0);                     person_pic.setvisibility(0);                      userconnections();                     userdetails();                    }               }         }.execute();         mprograss.dismiss();      }      @override     protected void onnewintent(intent intent) {         finishauthenticate(intent.getdata());     }        public void userdetails(){           if(person.getpictureurl()!=null){             pic_url = person.getpictureurl().tostring();             imageloader.displayimage(pic_url, person_pic);                           }else{             person_pic.setimageresource(r.drawable.ic_launcher);             }          /*************** person details summary/experience/education/languages/skills/contacts/interests **********************/          if (person.getsummary()!=null) {             prof_summary    = person.getsummary();         }          prof_experience="";         (position position:person.getpositions().getpositionlist())         {             if(position.isiscurrent()){                 startdate=months[(int) (position.getstartdate().getmonth()-1)]+"-"+position.getstartdate().getyear();                 enddate="currently working";             }else{                 startdate=months[(int) (position.getstartdate().getmonth()-1)]+"-"+position.getstartdate().getyear();                 enddate=months[(int) (position.getenddate().getmonth()-1)]+"-"+position.getenddate().getyear();             }             prof_experience=prof_experience+"<b>" +"position :"+"</b>"+position.gettitle()+"<br><b>" +"company :"+ "</b>"+ position.getcompany().getname()+"<br><b>" +"start date:"+ "</b>"+ startdate +"<br><b>" +"end date:"+ "</b>"+ enddate +"<br>"+"<br>";         }          prof_education="";         (education education:person.geteducations().geteducationlist())          {             prof_education=prof_education +"<b>" +"gaduation :"+ "</b>" +education.getdegree()+"<br><b>" +"institute :"+ "</b>" +education.getschoolname()+ "<br><b>" +"graduation year :"+ "</b>" +education.getenddate().getyear()+"<br>"+"<br>";         }         prof_languages="";         for(language language:person.getlanguages().getlanguagelist())         {             prof_languages=prof_languages+language.getlanguage().getname()+"\n";         }          prof_skills="";         for(skill skill:person.getskills().getskilllist())         {             prof_skills=prof_skills+skill.getskill().getname()+"\n";         }           prof_contatct="";         phonenumbers contactinfo=person.getphonenumbers();         if(contactinfo!=null ){             for(phonenumber phoneno:person.getphonenumbers().getphonenumberlist())             {                 prof_contatct=prof_contatct+ phoneno.getphonenumber().tostring();             }         }          if(person.getemailaddress()!=null){             prof_email=person.getemailaddress();         }         prof_interests = person.getinterests();         prof_birthdate= person.getdateofbirth().getday()+"-"+ months[(int) (person.getdateofbirth().getmonth()-1)]+"-"+person.getdateofbirth().getyear();        }       public void userconnections(){         final set<profilefield> connectionfields = enumset.of(profilefield.id,                  profilefield.first_name,                  profilefield.last_name,                  profilefield.headline,                 profilefield.industry,                 profilefield.picture_url,                  profilefield.main_address,                 profilefield.location,                 profilefield.location_country,                  profilefield.location_name,                  profilefield.summary,                 profilefield.educations,                 profilefield.educations_degree,                 profilefield.educations_end_date,                 profilefield.educations_field_of_study,                 profilefield.educations_id,                 profilefield.educations_school_name,                 profilefield.educations_start_date,                  profilefield.languages,                 profilefield.languages_id,                 profilefield.languages_language,                 profilefield.languages_language_name,                  profilefield.positions,                 profilefield.positions_company,                 profilefield.positions_company_industry,                 profilefield.positions_company_name,                 profilefield.positions_end_date,                 profilefield.positions_is_current,                 profilefield.positions_start_date,                 profilefield.positions_summary,                 profilefield.positions_title,                  profilefield.skills,                 profilefield.interests,                 profilefield.phone_numbers,                 profilefield.email_address,                 profilefield.date_of_birth,                 profilefield.public_profile_url                 );          connections = client.getconnectionsforcurrentuser(connectionfields);          (person person : connections.getpersonlist()) {             itemslist.add(person);         }          connection_adapter myadpter=new connection_adapter();         connections_list.setadapter(myadpter);         connections_list.setvisibility(0);         connections_list.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                  /*connections list item position selection*/                 person = itemslist.get(position); /*                 map<searchparameter, string> searchparameters = new enummap<searchparameter, string>(searchparameter.class);                  searchparameters.put(searchparameter.keywords, "university of x");                           people people = client.searchpeople(searchparameters);                  system.out.println("total search result:" + people.getcount());                   (person person : people.getpersonlist()) {                      system.out.println(person.getid() + ":" + person.getfirstname() + " " +                      person.getlastname() + ":" + person.getheadline());                  }*/                   /*                 people people = client.searchpeople(searchparameters);                 (person persons : people.getpersonlist()) {                     persons = client.getprofilebyapirequest(persons.getapistandardprofilerequest());                 }                 log.i("my persons list", ""+person);*/                  /*intent mycon=new intent(linkcon_main.this, con_profile.class);                 mycon.putextra("conid", con_name);                 startactivity(mycon); */                  con_name=person.getfirstname()+" "+person.getlastname();                 system.out.println("name:"+con_name);                  con_headline=person.getheadline();                 system.out.println("designation:"+con_headline);                  con_industry=person.getindustry();                 system.out.println("industry:"+con_industry);                  location locallocation = person.getlocation();                 if (locallocation != null){                     con_location=string.format("%s", new object[] { locallocation.getname() });                     system.out.println("con_loaction:"+con_location);                 }                  /*****picture/name/industry/location tested ok******/                  /********need summary/experience/education/skills/languages/dateofbirth/phonenumber/email**********/                  toast.maketext(linkcon_main.this, "name:"+" "+con_name +"\n"+"position:"+" "+con_headline+"\n"+"industry:"+" "+con_industry+"\n"+"locations:"+" "+con_location, toast.length_long).show();              }//onitemclick         });     }      public class connection_adapter extends baseadapter{          @override         public int getcount() {             // todo auto-generated method stub             return itemslist.size();         }          @override         public object getitem(int position) {             // todo auto-generated method stub             return position;         }          @override         public long getitemid(int position) {             // todo auto-generated method stub             return position;         }          @override         public view getview(int position, view convertview, viewgroup parent) {             // todo auto-generated method stub             viewholder holder = null;             if(convertview==null){                 convertview = inflater.inflate(r.layout.list_row,                         null);                 holder = new viewholder();                 holder.con_itenames = (textview) convertview                         .findviewbyid(r.id.connection_name);                 holder.con_designations = (textview) convertview                         .findviewbyid(r.id.connection_headline);                 holder.con_itemimage = (imageview) convertview                         .findviewbyid(r.id.connection_image);                 holder.con_locationad = (textview) convertview                         .findviewbyid(r.id.connection_location);                   convertview.settag(holder);             } else {                 holder = (viewholder) convertview.gettag();             }             setdata(holder,position);             return convertview;         }          protected context getbasecontext() {             // todo auto-generated method stub             return null;         }          public void setdata(final viewholder holder, int position) {             final person con_details = itemslist.get(position);             holder.con_itenames.settext(con_details.getfirstname()+" "+con_details.getlastname());             holder.con_designations.settext(con_details.getindustry());              location locallocation = con_details.getlocation();             if (locallocation != null){                 con_location=string.format("%s", new object[] { locallocation.getname() });             }             holder.con_locationad.settext(con_location);             holder.con_itenames.settag(con_details);             if (con_details.getpictureurl()!=null) {                 imageloader.displayimage(con_details.getpictureurl(), holder.con_itemimage, options);             }else {                 holder.con_itemimage.setimageresource(r.drawable.ic_launcher);}         }          public void setlistitems(arraylist<person> newlist) {             itemslist = newlist;             notifydatasetchanged();         }     }         public class viewholder{         textview con_itenames,con_designations, con_locationad;         imageview con_itemimage;     }      private void userpersons() {         // todo auto-generated method stub          intent user_prof = new intent(linkcon_main.this, user_profile.class);          user_prof.putextra("pic", pic_url);         user_prof.putextra("name", prof_name);         user_prof.putextra("headline", prof_headline);         user_prof.putextra("locations", prof_location);         user_prof.putextra("industry", prof_industry);         user_prof.putextra("summary", prof_summary);         user_prof.putextra("languages", prof_languages);         user_prof.putextra("experience", prof_experience);         user_prof.putextra("education", prof_education);         user_prof.putextra("skills", prof_skills);         user_prof.putextra("interests", prof_interests);         user_prof.putextra("dateofbirth", prof_birthdate);         user_prof.putextra("phoneno", prof_contatct);         user_prof.putextra("email", prof_email);          startactivity(user_prof);        }   } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -