2016-05-22 3 views
1

Я действительно очень надеюсь, что кто-то может помочь мне через это здесь. Я работаю над этим все выходные, чтобы заставить код работать, и я обещаю моему боссу, что он будет работать до понедельника.вызов функции с EventListener

UPDATE

<!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. Когда я нажимаю здесь, я могу войти в LinkedIn. Когда я вошел в систему, я получаю пустую страницу, и в моей консоли я не получаю никаких ошибок только:

Но как я могу получить функцию совместного доступа?

+0

где в ближайшие из ? это аргумент для функции? – Kannaj

+0

Hello Kunkka. На самом деле я на самом деле не на 100% безопасен. Это находится в файле api: https://developer.linkedin.com/docs/share-on-linkedin –

+0

, если вам не хватает части входа/входа, указанной в документах? '' '' '' – 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 (это еще ошибка, но теперь при запросе акций):

<!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 в разделе «Поделиться с определенными значениями», чтобы вы могли настроить то, что хотите поделиться. Могу ли я также реализовать это? Я получаю ошибку 400 Плохой запрос IN.API.Raw («/ people/~/shares? Format = json»), когда я вызываю shareContent() –

Смежные вопросы