我想使用Phonegap将Likedin连接到我的应用程序。我已经搜索了插件和OAuth程序,没有关于那个的更新。任何机构都知道如何使用Phonegap App登录并获取Likedin详细信息。
答案 0 :(得分:3)
截至目前,linkdin插件不适用于phonegap,但您可以使用Inappbrowser插件手动实现此功能。
我使用了带有phonegap的angularjs作为其非常棒的javascript框架。下面的代码会给你一些想法。
$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));
}
})
}
}
});
};
希望这会有所帮助...... 感谢
答案 1 :(得分:1)
截至目前,没有适用于phonegap的插件。但您可以使用Javascript API连接Linkedin帐户。点击此链接Linkedin Javascript API &安培; Sign in Tutorial 您可以使用inappbrowser插件调用此API。休息你可以借助javascript和会话管理来管理它。希望这有帮助。!