2015-04-08 34 views
0

以下是我們的要求: 在鏈接輸入(URL,標題,摘要和圖像)中共享頁面的動態更改內容。 問題陳述: 1.除圖像的所有其他內容得到在鏈接IN 方法1共享:使用鏈接在共享網址在鏈接輸入中使用元標記共享動態變化圖像og:圖像不起作用

<a target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=<<OUR URL>>&title=<<Our TITLE>>&summary=<<OUR SUMMARY>>">Share</a> 

問題: 1. URL上面不具有參數來傳遞如標題圖像,總結etc.It被取出由它具有財產meta標籤內容的圖像「OG:圖像」,在頁面

<meta property="og:image" content="<<IMAGE URL>>">enter code here 

由於圖像在頁面動態變化的,我們試圖使用動態更改此元標記的內容jQuery的。但是,當新的共享窗口打開時,它試圖獲取元標記中可用的默認圖像,而不是使用jQuery設置的默認圖像。

方法二:使用AJAX後提交行動

function shareOnLinkedInTest() { 
    var dataJson= {"share": { 
      "comment": "Posting from the API using XML", 
      "content": { 
       "title": "A title for your share", 
       "submitted-url": "http://developer.linkedin.com", 
       "submitted-image-url": 
       "ImageURL", 
      }, 
      "visibility": { "code": "anyone" } 
     }}; 


$.ajax({ 
    type: 'POST', 
     crossDomain : true, 
    contentType: "application/json", 
     dataType:"jsonp", 
     jsonp: 'jsonp-callback', 
     url: "https://api.linkedin.com/v1/people/~/shares?format=json", 
     data:dataJson, 
     success: function(data) { 
     alert("it works>>>>>>>>>>>>>>"+data); 
    }, 
     error : function (xhr, ajaxOptions, thrownError){ 
      alert("error"); 
      console.log(xhr);   
     console.log(thrownError); 
     } 
    }); } 

問題: 這是拋出401 -Unauthorized例外,因爲沒有選擇在上面的腳本中輸入用戶憑證,同時共享內容

在分享內容時,經歷了Linked In存在緩存問題的各種參考站點時已經觀察到。

https://www.wix.com/support/html5/ugc/e828aa26-d50b-4e5a-a982-ff563ca7e3dd/061f3e24-55e1-418d-ab65-9d6b0457b863 Getting old image while sharing page in LinkedIn

可以在這個任何人的幫助,請????

由於事先 薩里薩

回答

0

LinkedIn的履帶不執行頁的Javascript,所以如果你是靠客戶端代碼來設置meta標籤的價值,它不會被拾起的時候LinkedIn抓住分享的頁面。該值必須靜態渲染到頁面中(如果它必須是動態值,則必須在後端選擇並將其呈現到頁面中)。

關於第二種方法,您必須在嘗試發佈共享前對用戶進行身份驗證,這就是爲什麼當您嘗試時出現401未授權錯誤的原因。關於如何在https://developer.linkedin.com/docs/rest-api

處提供經過驗證的REST API調用的更多信息
相關問題