Linkedin人物搜索Javascript API不返回任何结果

时间:2011-11-17 07:51:16

标签: javascript api search linkedin

我正在使用linkedin JS API

我正在尝试执行people search,它没有返回任何内容

代码:

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
        api_key: --my api key--
        onLoad: onLinkedInLoad
        authorize: true
</script> 

<script type="text/javascript">

        function onLinkedInLoad() {
            IN.Event.on(IN, "auth", onLinkedInAuth);
        }

        function onLinkedInAuth() {

            IN.API.PeopleSearch()
            .fields("firstName", "lastName", "distance")
            .params({"company-name":"infosys"})
            .result(displayPeopleSearch)
            .error(displayPeopleSearchError);

        }

        function displayPeopleSearch(){

            var peopleSearchDiv = document.getElementById("peoplesearch");

            var members = peopleSearch.people.values;


            for (var member in members) {
            // but inside the loop, everything is the same
            // extract the title from the members first position
                peopleSearchDiv.innerHTML += "<p>" + members[member].firstName + " " + members[member].lastName + " is a " + members[member].positions.values[0].title + ".</p>";

            }
        }

任何帮助,我做错了什么?

我正在关注此tutorial

1 个答案:

答案 0 :(得分:3)

在这一行中,您使用的是未在任何地方声明的变量peopleSearch

var members = peopleSearch.people.values;

您必须向函数function displayPeopleSearch()

添加参数
function displayPeopleSearch(peopleSearch){

        var peopleSearchDiv = document.getElementById("peoplesearch");

        var members = peopleSearch.people.values;


        for (var member in members) {
        // but inside the loop, everything is the same
        // extract the title from the members first position
            peopleSearchDiv.innerHTML += "<p>" + members[member].firstName + " " + members[member].lastName + " is a " + members[member].positions.values[0].title + ".</p>";

        }
    }

d