如何连接Likedin与phonegap [英] How to connect Likedin with phonegap

查看:150
本文介绍了如何连接Likedin与phonegap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接Likedin与我的应用程序使用Phonegap.I搜索插件和OAuth过程,没有更新关于这一点。任何身体了解如何登录,并使用Phonegap应用程序获取Likedin的详细信息。

I want to connect Likedin with my app using Phonegap.I have search for plugins and OAuth procedure,there is no update Regarding that.Does any body Know how to Log In and get Likedin details using Phonegap App.

推荐答案

现在linkdin插件不适用于phonegap,但您可以使用Inappbrowser插件手动实现。

As of now linkdin plugin is not available for phonegap but you can manually implement this with Inappbrowser plugin.

我使用angularjs与phonegap作为它的真棒javascript框架。下面的代码会给你一些想法。

I have used angularjs with phonegap as its just awesome javascript framework. Below code will give you some idea.

$scope.linkdin = function (title,description,image,index) {
        //window.plugins.socialsharing.share('Message only');
        $scope.linkdinUrl = "http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png";
        $scope.linkdinTilte = title;
        $scope.linkidnSummary = description;
        $scope.linkidnImage =  "http://122.182.14.107:8080/GESmartCatalog/feature/image/"+$scope.fm_data[index].id+".png";
        //alert($scope.linkidnImage)
        if(localStorage.getItem("linkedinWindowExpiry") == '0')
        {
            localStorage.setItem("linkedinWindowValue", "0")
        }

        if(localStorage.getItem("linkedinWindowValue") == '0' && localStorage.getItem("linkedinWindowExpiry") == '0')
        {
            localStorage.setItem("linkedinWindowValue", "1");
            $scope.linkedinWindowText = 'location=no';
        }
        else
        {
            // alert("sfgfsg");
            // alert(localStorage.getItem("linkedinWindowExpiry"));
            $scope.linkedinWindowText = 'location=no';  
        }



        $rootScope.shareXmlLinkedin = "<?xml version='1.0' encoding='UTF-8' ?>"+
                                        "<share>"+
                                          "<comment></comment>"+
                                          "<content>"+
                                             "<title>"+$scope.linkdinTilte+"</title>"+
                                            "<description>"+$scope.linkidnSummary+"</description>"+
                                           "<submitted-url>"+$scope.linkdinUrl+"</submitted-url>"+
                                            "<submitted-image-url>"+$scope.linkidnImage+"</submitted-image-url>"+
                                         "</content>"+
                                         "<visibility>"+
                                            "<code>anyone</code>"+
                                          "</visibility>"  +
                                        "</share>";

        var ref = window.open('https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=gw80y7867ukx&scope=rw_nus w_messages r_fullprofile&state=zwdkLai5urm0AscP&redirect_uri=http://www.softwebcms.com','_blank',$scope.linkedinWindowText);
            ref.addEventListener('loadstart', function(e){

                if(e.url.indexOf('?code=') >=0 ){
                    if(e.url.match(/=[^]+&/)){
                        var code = e.url.match(/=[^]+&/)[0].substring(1).replace('&','');
                       // alert(code)
                        window.sessionStorage.setItem('code', code);

                        ref.close();

                        $.ajax({
                            url: 'https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code='+code+'&redirect_uri=http://www.softwebcms.com&client_id=gw80y7867ukx&client_secret=zwdkLai5urm0AscP',
                            success: function(a){
                                //alert(JSON.stringify(a));
                                    //alert(a.access_token);

                                    localStorage.setItem("linkedinWindowExpiry", a.expires_in);
                                        //alert($rootScope.shareXmlLinkedin);   
                                     $.ajax({
                                            url : 'https://api.linkedin.com/v1/people/~/shares?oauth2_access_token='+a.access_token,
                                            type: 'POST',
                                            method : 'POST',
                                            headers : {
                                                'Content-Type'  : 'application/xml'
                                            },
                                            data: $rootScope.shareXmlLinkedin,
                                            success: function(a){

                                                $modal.open({
                                                    template: "<div class='modal-body'><div style='width:100%; text-align:center; '><h3 style='text-align:center;'>Added to Linkedin</h3></div>",
                                                    windowClass: "main_popup_width dialog",
                                                    controller: function ($scope, $rootScope, $modalInstance) {

                                                                setTimeout(function(){$rootScope.wtbfavactive="123";$modalInstance.dismiss('cancel')},3000);

                                                              },
                                                    }); 
                                            },
                                            error: function(a){
                                                console.log(JSON.stringify(a))
                                                //alert(JSON.stringify(a))
                                                $modal.open({
                                                    template: "<div class='modal-body'><div style='width:100%; text-align:center; '><h3 style='text-align:center;'>Already posted to Linkedin</h3></div>",
                                                    windowClass: "main_popup_width dialog",
                                                    controller: function ($scope, $rootScope, $modalInstance) {

                                                                setTimeout(function(){$rootScope.wtbfavactive="123";$modalInstance.dismiss('cancel')},3000);

                                                              },
                                                    }); 
                                            }
                                        })

                            },
                            error: function(a){
                                //alert(JSON.stringify(a))
                                console.log(JSON.stringify(a));
                            }
                        })
                    }
                }
            });
      };

希望这有助于...
感谢

Hope this helps... Thanks

这篇关于如何连接Likedin与phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆