2016-05-22 2 views
1

私は実際に誰かがここでこれを手伝ってくれることを願っています。私はこの週末の間、このコードを動作させるために取り組んできました。そして、私は上司に月曜の朝まで働くことを約束します。EventListenerで関数を呼び出す

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <meta charset="utf-8" /> 
    <!--<script type="text/javascript" src="http://code.jquery.com/jquery-1.5b1.js"></script>--> 
    <script type="text/javascript" src="http://platform.linkedin.com/in.js"> 
    api_key: my_API_key 
    authorize: true 
    onLoad: shareContent 
    </script> 

</head> 
<body> 

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

    <script> 
      // Setup an event listener to make an API call once auth is complete 
      function onLinkedInLoad() { 
       IN.Event.on(IN, "auth", shareContent); 
      } 

      // 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 share content on LinkedIn 
      function shareContent() { 

       // Build the JSON payload containing the content to be shared 
       var payload = { 
        "comment": "Check out developer.linkedin.com! http://linkd.in/1FC2PyG", 
        "visibility": { 
         "code": "anyone" 
        } 
       } 

       IN.API.Raw("/people/~/shares?format=json") 
       .method("POST") 
       .body(JSON.stringify(payload)) 
       .result(onSuccess) 
       .error(onError); 
      } 


    </script> 

</body> 
</html> 

私はLinkedInのボタンでサインを取得し、このコードを実行するUPDATE。ここをクリックするとLinkedInにログインします。私がログインしているときに空白のページが表示され、コンソールにエラーが表示されません:

しかし、どのようにして共有機能をポップアップ表示できますか?

+0

を?それは関数の引数ですか? – Kannaj

+0

こんにちはKunkka。私は実際にそれを100%保証していません。 apiにあります:https://developer.linkedin.com/docs/share-on-linkedin –

+0

ドキュメントに指定されたin/login部分がありませんか? '' '' '' – Kannaj

答えて

-1

<script type="text/javascript" src="http://platform.linkedin.com/in.js"> 
    api_key: My_API_Key_without_quotes 
    onLoad: Linkedin.init 
</script> 

の上にこのスクリプトを追加し、ここに

EDIT(これはまだエラーを持っていますが、今で共有要求で)あなたのAPIの初期化を移動:INから来ている

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <meta charset="utf-8" /> 

<script type="text/javascript"> 
    function addListeners() { 
     if(window.addEventListener) { 
      document.getElementById('mybtn').addEventListener("click", shareContent, false); 
     } else if(window.attachEvent) { 
      document.getElementById('mybtn').attachEvent("onclick", shareContent); 
     } 
    } 
    // Setup an event listener to make an API call once auth is complete 
    function onLinkedInLoad() { 
     IN.Event.on(IN, "auth", shareContent); 
    } 

    // 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 share content on LinkedIn 
    function shareContent() { 

     // Build the JSON payload containing the content to be shared 
     var payload = { 
     "comment": "Check out developer.linkedin.com! http://linkd.in/1FC2PyG", 
     "visibility": { 
      "code": "anyone" 
     } 
     }; 

     IN.API.Raw("/people/~/shares?format=json") 
     .method("POST") 
     .body(JSON.stringify(payload)) 
     .result(onSuccess) 
     .error(onError); 
    } 

    document.addEventListener("DOMContentLoaded", addListeners); 

</script> 

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

</head> 
<body> 
    <button id="mybtn">Try Me</button> 
</body> 
</html> 
+0

あなたの答えはありがとうございます。私はちょっと混乱しているので、それは残念です。私はちょうど私の質問を更新したが、それはあなたが意味するものだとは思わない? –

+0

私は自分の答えを編集して動作させました。しかし、私はまだエラー400に直面しています。私たちが共有を要求したときのリクエストが悪い:IN.API.Raw( "/ people /〜/ shares?format = json") –

+0

もう一度、ありがとう。私はいつもそのエラーがあることにあなたに同意します。私はちょうど私の質問を更新した。今すぐLinkedinボタンが呼び出されます。クリックすると、ログインできるLinkedInからポップアップボックスが表示されます。リンクは現在LinkedIn上で実際に共有されています。だから私はhttps://developer.linkedin.com/docs/share-on-linkedinの "特定の値と共有する"の下に、あなたが共有したいものをカスタマイズすることができます。私はそれを実装することもできますか?私がshareContent()を呼び出すと、エラー400が返されます。IN.API.Raw( "/ people /〜/ shares?format = json" –