Wednesday, August 15, 2012

Linkedin Java script API - Company search and People search Sample code

  function CompanySearch(CompanyName) {
       
            if (IN.User.isAuthorized()) {
                var keywords = CompanyName.toString();
                IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url,logo-url,description))")
              .params({ "keywords": keywords })

              .result(function (result) { /* handle result */
                  var Companies = result;
                  slCtl.Content.companySearch.ShowCompanyProfile(JSON.stringify(Companies));
              })

              .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); });
            }
            else {
                IN.User.authorize(function () {
                    var keywords = CompanyName.toString();
                    IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url,logo-url,description))")
              .params({ "keywords": keywords })
              .result(function (result) { /* handle result */
                  var Companies = result;
                  slCtl.Content.companySearch.ShowCompanyProfile(JSON.stringify(Companies));
              })
              .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); });


                });
            }

        }




        function PeopleSearchval(param1, firstname, lastname, company) {
         
            if (IN.User.isAuthorized()) {
                var keywords = param1.toString();
                var fname = firstname.toString();
                var lname = lastname.toString();
                var companyname = company.toString();

                IN.API.PeopleSearch()
         .fields("id", "firstName", "lastName", "distance", "siteStandardProfileRequest", "picture-url", "positions:(company:(name),title)")
                 .params({ "keywords": keywords, "count": 25, "sort": "relevance", "first-name": fname, "last-name": lname, "company-name": company })
         .result(displayPeopleSearches)

         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
             );
//                      var listCount = 20;
//                    url = "/people-search:(people:(id,first-name,last-name,picture-url,distance,siteStandardProfileRequest),num-results)?facets=network&facet=network,F,S,A,O"
//                    url += '&count=25' + listCount;
////                    url += '&keywords=' + keywords;
//                    url += '&first-name=' + "";
//                    url += '&last-name=' + "";
//                    url += '&company-name=' + companyname;

//                    //        url += "&facet=location," + theLocation;

//                    IN.API.Raw(url)
//                .result(displayPeopleSearches)
//         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
//             );
            }
            else {
                //            if (IN.User.authorize()) {
                IN.User.authorize(function () {
                    var keywords = param1.toString();
                    var fname = firstname.toString();
                    var lname = lastname.toString();
                    var companyname = company.toString();

                    IN.API.PeopleSearch()
         .fields("id", "firstName", "lastName", "distance", "siteStandardProfileRequest", "picture-url", "positions:(company:(name),title)")
                 .params({ "keywords": keywords, "count": 20, "sort": "distance", "facet": "network", "first-name": fname, "last-name": lname, "company-name": company })
         .result(displayPeopleSearches)
         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
             );

                    //            }
                });

            }

            //        var listCount = 20;
            //        url = "/people-search:(people:(id,first-name,last-name,picture-url,distance,siteStandardProfileRequest),num-results)?facets=network&facet=network,F,S,A,O"
            //        url += '&count=25' + listCount;
            //        url += '&keywords=' + keywords;
            //        url += '&first-name=' + fname;
            //        url += '&last-name=' + lname;

            //        //        url += "&facet=location," + theLocation;

            //        IN.API.Raw(url)
            //    .result(displayPeopleSearches);
        }
//        var relations = new Array();

//        var membervalues = null;
//        var members = null;
//        var relval = null;
        function displayPeopleSearches(peopleSearchValues) {
//            membervalues = peopleSearchValues;

            slCtl.Content.contactSearch.ShowPeoples(JSON.stringify(peopleSearchValues));
          }
        function getrelations(idvalue) {
        
            IN.API.Raw('/people/id=' + idvalue + ':(id,distance,relation-to-viewer:(distance,related-connections:(id,distance,first-name,last-name,picture-url)))').result(display);


        }
        function display(searchresults) {
          
//            var relatioships = JSON.stringify(searchresults);
            slCtl.Content.contactSearch.ShowRelations(JSON.stringify(searchresults));
        }
  function CompanySearch(CompanyName) {
       
            if (IN.User.isAuthorized()) {
                var keywords = CompanyName.toString();
                IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url,logo-url,description))")
              .params({ "keywords": keywords })
              .result(function (result) { /* handle result */
                  var Companies = result;
                  slCtl.Content.companySearch.ShowCompanyProfile(JSON.stringify(Companies));
              })
              .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); });
            }
            else {
                IN.User.authorize(function () {
                    var keywords = CompanyName.toString();
                    IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url,logo-url,description))")
              .params({ "keywords": keywords })
              .result(function (result) { /* handle result */
                  var Companies = result;
                  slCtl.Content.companySearch.ShowCompanyProfile(JSON.stringify(Companies));
              })
              .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); });


                });
            }

        }




        function PeopleSearchval(param1, firstname, lastname, company) {
            // Call the PeopleSearch API with the viewer's keywords
            // Ask for 4 fields to be returned: first name, last name, distance, and Profile URL
            // Limit results to 10 and sort by distance
            // On success, call displayPeopleSearch(); On failure, do nothing.


            //        IN.User.authorize(function () {//            IN.API.Profile("me")
            //            //    .result(function (result) {
            //            //        alert(JSON.stringify(result));
            //            //    });

            //        });
            //               IN.Event.on(IN, "auth", onLinkedInAuth);
            if (IN.User.isAuthorized()) {
                var keywords = param1.toString();
                var fname = firstname.toString();
                var lname = lastname.toString();
                var companyname = company.toString();

                IN.API.PeopleSearch()
         .fields("id", "firstName", "lastName", "distance", "siteStandardProfileRequest", "picture-url", "positions:(company:(name),title)")
                 .params({ "keywords": keywords, "count": 25, "sort": "relevance", "first-name": fname, "last-name": lname, "company-name": company })
         .result(displayPeopleSearches)
         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
             );
//                      var listCount = 20;
//                    url = "/people-search:(people:(id,first-name,last-name,picture-url,distance,siteStandardProfileRequest),num-results)?facets=network&facet=network,F,S,A,O"
//                    url += '&count=25' + listCount;
////                    url += '&keywords=' + keywords;
//                    url += '&first-name=' + "";
//                    url += '&last-name=' + "";
//                    url += '&company-name=' + companyname;

//                    //        url += "&facet=location," + theLocation;

//                    IN.API.Raw(url)
//                .result(displayPeopleSearches)
//         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
//             );
            }
            else {
                //            if (IN.User.authorize()) {
                IN.User.authorize(function () {
                    var keywords = param1.toString();
                    var fname = firstname.toString();
                    var lname = lastname.toString();
                    var companyname = company.toString();

                    IN.API.PeopleSearch()
         .fields("id", "firstName", "lastName", "distance", "siteStandardProfileRequest", "picture-url", "positions:(company:(name),title)")
                 .params({ "keywords": keywords, "count": 20, "sort": "distance", "facet": "network", "first-name": fname, "last-name": lname, "company-name": company })
         .result(displayPeopleSearches)
         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
             );

                    //            }
                });

            }

            //        var listCount = 20;
            //        url = "/people-search:(people:(id,first-name,last-name,picture-url,distance,siteStandardProfileRequest),num-results)?facets=network&facet=network,F,S,A,O"
            //        url += '&count=25' + listCount;
            //        url += '&keywords=' + keywords;
            //        url += '&first-name=' + fname;
            //        url += '&last-name=' + lname;

            //        //        url += "&facet=location," + theLocation;

            //        IN.API.Raw(url)
            //    .result(displayPeopleSearches);
        }
//        var relations = new Array();

//        var membervalues = null;
//        var members = null;
//        var relval = null;
        function displayPeopleSearches(peopleSearchValues) {
//            membervalues = peopleSearchValues;

            slCtl.Content.contactSearch.ShowPeoples(JSON.stringify(peopleSearchValues));
          }
        function getrelations(idvalue) {
        
            IN.API.Raw('/people/id=' + idvalue + ':(id,distance,relation-to-viewer:(distance,related-connections:(id,distance,first-name,last-name,picture-url)))').result(display);


        }
        function display(searchresults) {
          
//            var relatioships = JSON.stringify(searchresults);
            slCtl.Content.contactSearch.ShowRelations(JSON.stringify(searchresults));
        }
   

2 comments: