从LinkedIn Javascript API可靠地获取电子邮件

时间:2015-09-07 11:17:16

标签: javascript linkedin linkedin-jsapi

热衷于可靠地获取用户的电子邮件,这些来自LinkedIn的API文档中似乎没有任何内容。我有鳕鱼工作,抓住基本的配置文件,我已经尝试了我可以在网上找到的其他字段。但这不会返回任何东西。这是代码:

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

  </script>

<script type="text/javascript">
  // Setup an event listener to make an API call once auth is complete
    function onLinkedInLoad() {


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

    // Handle the successful return from the API call
    function onSuccess(data) {
        console.log(data);

    }

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

    // Use the API call wrapper to request the member's basic profile data
    function getProfileData() {
    var fields = ['firstName', 'lastName', 'emailAddress'];

       IN.API.Profile("me").fields(fields).result(onSuccess).error(onError);
    }
</script>

和HTML:

<script type="in/Login"></script>

我不知道当前版本是否可以返回电子邮件或电子邮件是用户设置,因此每个用户都有所不同。

1 个答案:

答案 0 :(得分:0)

您缺少范围的r_emailaddress:

<script type="text/javascript" src="//platform.linkedin.com/in.js">
       api_key: 11111111111
       onLoad:  onLinkedInLoad
       authorize: true
       scope: r_basicprofile r_emailaddress
</script>

还要确保使用正确的字段语法:

var fields = ['first-name', 'last-name', 'email-address'];

最后在LinkedIn开发者处检查您授予r_emailaddress访问权限的应用设置。