1

我是第一次做网站。对于任何愚蠢的问题,我很抱歉,但我真的没有背景。不过,我正在努力学习。我在 Weebly (www.i2i.network) 上开发了该网站,并尝试通过他们的 API 服务包含一个 LinkedIn 注册按钮,以监控正在使用该网站的人。

到目前为止,我复制并粘贴了我在 LinkedIn SDK 指南中找到的内容

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

<script type="text/javascript" src="//platform.linkedin.com/in.js">
    IN.User.logout(callbackFunction, callbackScope);
    api_key:   [API] //I put my API key here 
    authorize: true
    onLoad: onLinkedInLoad
    lang:      [LANG_LOCALE]
</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() {
        IN.API.Raw("/people/~").result(onSuccess).error(onError);
    }

</script>

该按钮第一次出现,它打开了与我的 LinkedIn 个人资料的连接。真令人兴奋!:D(极客)

在这一点上,我仍然不知道我是否从 LinkedIn API 服务中检索到任何数据,如果“是”,如何管理它们并可能将它们包含在 Intercom.io 中。

据我了解,我应该从 LinkedIn API 收到以下内容:

{
  "firstName": "Frodo",
  "headline": "Jewelery Repossession in Middle Earth",
  "id": "1R2RtA",
  "lastName": "Baggins",
  "siteStandardProfileRequest": {
    "url": "https://www.linkedin.com/profile/view?id=…"
  }
}

我真的收到答案了吗?我该如何阅读?如何在以下 Intercom.io 脚本中使用它?

<script>
  window.intercomSettings = {
    app_id: "k9sz4pfb",
    name: "Nikola Tesla", // Full name
    email: "nikola@example.com", // Email address
    created_at: 1312182000 // Signup date as a Unix timestamp
  };
</script>
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/k92zopfb';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>

我知道这可能是一个非常基本的问题,但我从零开始,我喜欢通过练习来学习......

此外,如果您对我可以逐步学习的网站或教程有任何建议,我们将不胜感激。

感谢您的帮助,

贾科莫

4

1 回答 1

0

仔细检查语法,但这应该可以帮助您入门。

// Use the API call wrapper to request the member's basic profile data
 function getProfileData() {
    var dataOutput = 


      // I added the callback event DONE. This assures the data method is called when the this API call is successful and complete.
     var dataOutput =    IN.API.Raw("/people/~").result(onSuccess).error(onError).done( {

       if (dataOutput != null) {
          DoSomethingWithYourData(dataOutput);
       }
    });

 }

  function DoSomethingWithYourData(dataOutput) {
    console.log(dataOutput);
    // Parse your data or assign it to a control. do whatever here.
 }

为了回答您的其他问题,您可以将其添加到 JS 脚本文件并在其他页面上引用它,但您必须保持添加到此脚本文件中的任何控件 ID/类名相同,所以我的提示是保持这个文件非常通用,因此它不依赖于其他任何东西,只处理使用 LinkedIn 的数据。

我推荐这些链接以供进一步阅读,以便您可以扩展您的代码。

jQuery解析JSON

jQuery AJAX

jQuery 回调

于 2015-09-25T14:40:05.840 回答