【问题标题】:Linkedin Api dynamic parameter passingLinkedin Api 动态参数传递
【发布时间】:2018-01-31 11:22:11
【问题描述】:

我有一个 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 变量中,我正在获取公共配置文件的url 一个正在查看的linkedin 配置文件。

现在我想要的是我有一个服务器端代码,我必须在其中提供使用linkedin api的网址。

服务器端代码 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() 方法是在控制器中定义的。

    $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 文件中传递参数,它会引发错误。

【问题讨论】:

    标签: angularjs google-chrome linkedin-api


    【解决方案1】:

    我得到了答案。我使用 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);
        }
    );
    

    }

    【讨论】:

      猜你喜欢
      • 2020-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      • 2018-09-01
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多