我正在使用以下指令,并使用linkedin触发sigup,这将在登录窗口中进行链接。在那里我们进行登录并获取基本信息。但是出于验证目的,我需要从窗口中提取Access令牌。我找不到它作为回应。 https://www.linkedin.com/uas/oauth/authorize?oauth_token=11--223e4fc1-a5ca-477c-b5ca-f6d448f75e1e&state= 在这里,我们获得了访问令牌。如何获取它,需要准则
指令:
app.directive('linkedinLogin', ['$rootScope', '$interval',
function ($rootScope, $interval) {
return {
restrict: 'AE',
replace: true,
templateUrl: 'view/angular-linkedin-login-ptl.html',
scope: true,
compile: function (tElem, tAttrs) {
var linkedinLibLoaded = false,
linkedinLibInitialized = false;
window.linkedinLibInit = function () {
linkedinLibInitialized = true;
};
if (!linkedinLibLoaded) {
linkedinLibLoaded = true;
$.getScript("//platform.linkedin.com/in.js?async=true", function success() {
IN.init({
onLoad: "linkedinLibInit",
api_key: "2177219982198",
credentials_cookie: true
});
});
}
return function (scope, elem, attrs) {
console.log(scope);
console.log(elem);
console.log(attrs);
scope._buttonText = tAttrs.linkedinButtonText || 'Connect';
var _authorizedHandlerName = tAttrs.linkedinAuthorized || null;
var _authorizedHandler = _authorizedHandlerName ? scopescope[_authorizedHandlerName] : null;
var _profileDataHandlerName = tAttrs.linkedinProfileData || null;
var _profileDataHandler = _profileDataHandlerName ? scope[_profileDataHandlerName] : null;
var _successMsg = tAttrs.linkedinSuccessMsg || 'Linkedin Connection Authorized';
var ua = navigator.userAgent || 'unknown';
/* var _iOS = BrowserUtil.iOS();
var _iOSinterval = null;
if (!_authorizedHandler && !_profileDataHandler) {
throw "You must provide a 'linkedin-authorize' or 'linkedin-profile-data' on the scope.";
}
if (_iOS) {
// hide linkedin button for iOS because the LinkedIn JS API does not work, argh...
scope.linkedinMsg = scope.linkedinMsg || {};
scope.linkedinMsg.successMsg = true;
if (_profileDataHandler && typeof _profileDataHandler == 'function') {
scope[_profileDataHandlerName]({
hideLinkedin: true
});
} else {
scope[_authorizedHandlerName]({
hideLinkedin: true
});
}
return;
}*/
scope.linkedinMsg = scope.linkedinMsg || {};
scope.linkedinMsg.loaded = false;
scope.linkedinMsg.showButton = true;
scope.linkedinMsg.message = tAttrs.linkedinMsg || null;
scope.linkedinMsg.loading = false;
scope.linkedinMsg.errorMsg = null;
scope.linkedinMsg.successMsg = null;
scope.onLinkedinAuthClick = function ($ev) {
authorizeLinkedin();
};
var authorizeLinkedin = function () {
scope.linkedinMsg.loading = true;
if (IN.User.isAuthorized()) {
linkedinAuthorized();
} else {
IN.User.authorize(linkedinAuthorized);
/*
if(_iOS){
_iOSinterval = $interval(function(count){
var linkedinCookieFound = false;
var cookies = document.cookie.split(';');
for(var i=0;i<cookies.length;i++){
if(cookies[i].indexOf('linkedin_oauth') !== -1){
var cookieParts = cookies[i].split('=');
if(cookieParts[1] && _.isEmpty(cookieParts[1])){
linkedinCookieFound = true;
break;
}
}
}
if(linkedinCookieFound || count >= 9){
$interval.cancel(_iOSinterval);
linkedinAuthorized();
}
}, 200, 10);
}
*/
}
};
var linkedinAuthorized = function () {
if (_profileDataHandler && typeof _profileDataHandler == 'function') {
IN.API.Profile("me")
.fields('id', 'first-name', 'last-name', 'location', 'industry', 'headline', 'publicProfileUrl', 'email-address')
.result(function (data) {
console.log(data);
linkedinDataTransform(data);
})
.error(function (err) {
scope.linkedinMsg.loading = false
scope.linkedinMsg.errorMsg = 'Unable to get LinkedIn profile information. Please re-authorize.';
});
} else {
scope.linkedinMsg.loading = false;
scope.linkedinMsg.successMsg = _successMsg;
}
if (_authorizedHandlerName && typeof scope[_authorizedHandlerName] == 'function')
scope.$apply(scope[_authorizedHandlerName]({
auth: true
}));
};
var linkedinDataTransform = function (linData) {
debugger;
var linUser = ((linData && linData.values) ? linData.values[0] : null);
console.log(linUser);
if (linUser) {
scope.linkedinMsg.showButton = false;
scope.linkedinMsg.successMsg = _successMsg;
var data = {
user_email: linUser.emailAddress,
first_name: linUser.firstName,
last_name: linUser.lastName,
industry: linUser.industry,
headline: linUser.headline,
linkedin_id: linUser.id,
location: (linUser.location ? linUser.location.name : ''),
country_code: (linUser.location ? linUser.location.country.code : ''),
headline: linUser.headline,
publicProfileUrl: linUser.publicProfileUrl
};
if (_profileDataHandlerName && typeof scope[_profileDataHandlerName] == 'function') {
scope.$apply(scope[_profileDataHandlerName](data));
}
} else {
scope.linkedinMsg.loading = false;
scope.linkedinMsg.successMsg = 'Unable to get LinkedIn profile information. Please re-authorize.';
}
};
}
}
}
}
]);