从Linkedin api获取公司名称

时间:2014-09-23 09:44:30

标签: javascript api linkedin

我试图从特定网址和ID获取公司名称。所以,我需要让某个人当前所在的公司并展示它。到目前为止,这是我的代码:

> <script type="text/javascript">   function OnLinkedInFrameworkLoad() { 
> IN.Event.on(IN, "auth", OnLinkedInAuth); }
> 
>   function OnLinkedInAuth() {
>     IN.API.Profile("me").result(ShowProfileData);
>     IN.API.Raw("/people/~/picture-urls::(original)").result(highRes); }
> 
>     function highRes(images) {
>       var img = images.values[0];
>       $('#user').append('<img src="' + img + '">');
>     }
> 
>   function ShowProfileData(profiles) {
>     var member = profiles.values[0];
>     var id=member.id;
>     var firstName=member.firstName; 
>     var lastName=member.lastName; 
>     var imgSrc=member.pictureUrl; 
>     var headline=member.headline;
> 
>     var url = "http://api.linkedin.com/v1/people/" + id + "/picture-url";
>     console.log(member)
>     console.log(url)
>     console.log(company)
>     //use information captured above
> 
>     $("p").append("You are logged in as: ")
>     $('#firstName').append(firstName);
>     $('#lastName').append(lastName);
>     $('#company').append(company);
> 
>     var url_2 = "http://api.linkedin.com/v1/people/" + id + "~:(positions:(is-current,company:(name)))";
>     console.log(url_2);
>     } </script>

我遇到的麻烦是我只获取基本会员数据,并尝试使用其他网址获取公司名称,但网址不起作用..

1 个答案:

答案 0 :(得分:5)

好的,我解决了这个问题:

    <script type="text/javascript">

    function OnLinkedInFrameworkLoad() {
    IN.Event.on(IN, "auth", OnLinkedInAuth);
    // Use a larger login icon.
    $('a[id*=li_ui_li_gen_]').html('<img src="images/linkButton.png" height="40" width="130" border="0" class="linkButton" />');}

    function OnLinkedInAuth() {
    IN.API.Profile("me").fields(["firstName","headline","positions:(is-current,company:(name))"])
    .result(function(result) {
       var firstName = result.values[0].firstName;
       var company = result.values[0].positions.values[0].company.name;
       $('#firstName').append(firstName);
       $('#company').append(company);
    })
    IN.API.Raw("/people/~/picture-urls::(original)").result(highRes);
}

    function highRes(images) {
      var img = images.values[0];
      $('.linkedin').append('<img src="' + img + '" class="profile">');
      $('.mobile-linkedin').append('<img src="' + img + '"class="profile">');
      $("#guest").hide();
      $("#hide").hide();
    }

    function ShowProfileData(profiles) {
    var member = profiles.values[0];
    var id=member.id;
    var firstName=member.firstName;

    var url = "http://api.linkedin.com/v1/people/" + id + "/picture-url";
    //use information captured above
    }
    </script>