2016-07-01 57 views
1

我試圖實現LinkedIn共享API,我無法弄清楚這一點,因爲答覆並沒有真正說明發生了什麼。LinkedIn共享API返回「錯誤請求」錯誤

我實現了這個簡單的代碼在我的網站

<script type="text/javascript" src="//platform.linkedin.com/in.js"> 
    api_key: xxx 
    authorize: true 
    lang:  de_DE 
</script> 

    <script type="text/javascript"> 
    // 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); 
    } 

    function shareToLinkedIn(){ 
    var payload = { 
     "content": { 
      "title": "Test title", 
      "description": "test description", 
      "submitted-url": "http://www.someurl.com", 
      "submitted-image-url": "http://someurl.com/somepic.png" 
      }, 
      "visibility": { 
       "code": "connections-only" 
      } 
    }; 

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

我通過一個onClick事件調用此函數:

<a id="linkedin" href="#"onClick="shareToLinkedIn()"><i class="fa fa-linkedin-square" aria-hidden="true"></i> LinkedIn Test</a></li> 

但是,所有我得到如下回應:Object {errorCode: 0, message: "Invalid arguments: {S_400_BAD_REQUEST=Bad request}", requestId: "4JVTZJFVF1", status: 400, timestamp: 1467381898243}

+0

您是否發現問題?我在這裏也一樣:S –

+1

其實,是的:問題是,我沒有授權應用程序。當我實現這一點時,我認爲通過瀏覽器登錄LinkedIn已經足夠了。但是您實際上還必須實現應用程序的登錄按鈕,然後打開一個窗口,您必須授權「應用程序」將其發佈到您的個人資料。 (這實際上讓我忘記了這一點,因爲它似乎過於複雜,我試圖做。) – DCH

+1

好吧,感謝您的快速回復!你應該發佈這個作爲你自己的答案,並接受它:) –

回答

0

對此的回答:您還需要在您的網站上實施登錄按鈕,僅登錄到LinkedIn站點是不夠的。 所以,在這裏你「分享應用」實現在網站上,添加:

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

之後,按一下按鈕,授權的應用程序,它應該工作。