LinkedIn Javascript SDK 失败 Return 个职位

LinkedIn Javascript SDK Fail To Return Positions

我正在尝试使用 LinkedIn Javascript SDK 来检索一些信息,包括职位字段。我从互联网上复制了代码,但似乎有些地方不太对劲,因为我复制的代码没有 return 定位字段。我在 ApiGee 上试过它工作正常,它 return 编辑了职位列表,正如我所期望的那样。如果您查看下面的代码,您认为我遗漏了什么还是 javascript SDK 本身存在一些错误问题?

<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: yourapikey
authorize: true
onLoad: onLoad
</script>

<script type="text/javascript">
function onLoad() { 
    IN.Event.on(IN, "auth", getProfileData);
}

// Handle the successful return from the API call
function onSuccess(data) {
    alert(JSON.stringify(data));
}

// Handle an error response from the API call
function onError(error) {
    console.log(error);
}

// Use the API call wrapper to share content on LinkedIn

function getProfileData() {
    //alert(IN.ENV.auth.oauth_token);
    IN.API.Raw("/people/~:(id,positions)?format=json").result(onSuccess).error(onError);
}
</script>

Return 结果显示为:

{"id":"wQplQQjzLa","positions":{"_total":0}}

你好@John Hadikusumo, 好吧,我知道这个回复只会在一年后发生,但是,我也面临着 linkedin api 集成的一些问题,尤其是当涉及到 "positions" 对象值时。

显然,当我遇到错误时,这意味着正在使用其 linkedin 个人资料进行授权的用户,该特定用户尚未启动其体验详细信息,因此没有任何价值;

为了避免这个特殊问题,我所做的对我有帮助:

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

    function onSuccess(data) {
        console.log(data);
    }

    function onError(error) {
        console.log(error);
    }

    function getProfileData(){
        IN.API.Profile("me").fields(["firstName","lastName", "email-address", "positions"]).result(function(data) {
            var profileData = data.values[0];
            var profileFName = profileData.firstName;
            var profileLName = profileData.lastName;

            //this is the piece of code that helped me out;
            //might work for you as well;
            if(data.values[0].positions._total == "0" || data.values[0].positions._total == 0 || data.values[0].positions._total == undefined) {
                console.log("Error on position details");
                var profileCName = "Details Are Undefined";
            }
        else {
            var profileCName = profileData.positions.values["0"].company.name;
        }
        var profileEName = profileData.emailAddress;

        //and other logic/code continues...
    });
}

所以我希望这对你有所帮助。如果您遇到任何其他错误,请告诉我,如果我需要改进现有代码,我可以使用一些帮助。

干杯,祝你有美好的一天。