簡體   English   中英

Linkedin Api動態參數傳遞

[英]Linkedin Api dynamic parameter passing

我有一個chrome擴展程序及其內容腳本,該腳本在本地主機上運行

"content_scripts": [{
    "js": ["lib/jquery.js", "searching_helper.js"],
    "matches": [ "http://localhost:8089/*"]
}]

在search_helper.js中,我從另一個內容腳本獲取linkedin成員的公共個人資料網址。

   chrome.runtime.sendMessage({u:true},function(response) {
console.log(response.ans);
linkedinProfileUrl = response.ans.profileUrl;
console.log('linkedinProfileUrl' + linkedinProfileUrl);

});

在linkedinProfileUrl變量中,我正在獲取公共個人資料網址,正在查看的個人資料網址。

現在我想要的是我有一個服務器端代碼,在其中必須提供使用linkedin API的URL。

index.html文件的服務器端代碼

  <script type="text/javascript" src="https://platform.linkedin.com/in.js">
//here goes the api key, and the callback function
api_key: ******
onLoad: onLinkedInLoad
authorize: true
 </script>

在onload上運行的函數在linkedin.js文件中定義

     function onLinkedInLoad() {
    onLinkedInLogin();

}

    //execute on login event
   function onLinkedInLogin() {
//pass user info to angular
angular.element(document.getElementById("appBody")).scope().$apply(
    function($scope) {
        $scope.getLinkedInData();
    }
);

}

並且此getLinkedInData()方法是在controller中定義的。

    $scope.getLinkedInData = function() {
    if(!$scope.hasOwnProperty("userprofile")){
        IN.API.Profile("https://in.linkedin.com/in/latika").fields(
                [ "id", "firstName", "lastName", "pictureUrl",
                        "publicProfileUrl","positions","location","email-address"]).

在此IN.API.Profile(“ https://in.linkedin.com/in/latika ”)中,我想傳遞從內容腳本獲取的linkedinProfileUrl。 問題是,如果我在index.html文件中傳遞參數,則會引發錯誤。

我得到了答案。 我使用localStorage來獲取URL。

在search_helper.js中使用

localStorage.setItem('url', linkedinProfileUrl); 

然后在linkedin.js中使用

  function onLinkedInLogin() {
var url = localStorage.getItem('url');
//pass user info to angular
angular.element(document.getElementById("appBody")).scope().$apply(
    function($scope) {

        $scope.getLinkedInData(url);
    }
);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM