0
Как я могу настроить кнопку входа в LinkedIn? Кнопка LinkedIn по умолчанию невелика. Я пробовал коды в here, но я не мог заставить его работать.Настроить LinkedIn Кнопка входа
Мой код:
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: #my key
onLoad: onLinkedInLoad
</script>
Кнопка:
<script type="in/Login">
</script>
Скрипт:
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
// Handle the successful return from the API call
function onSuccess(data) {
var linkedInData = JSON.stringify(data);
logIn(linkedInData)
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Use the API call wrapper to request the member's basic profile data
function getProfileData() {
IN.API.Raw("/people/~").result(onSuccess).error(onError);
}
function logIn(data){
$.ajax({
type: "POST",
url: URL_POST_AJAX,
data: {
'data' : data,
},
success: function (response) {
window.location.href = response.next_page;
},
error: function (data) {
alert('failed');
}
});}
// CSRF code
function getCookie(name) {
var cookieValue = null;
var i = 0;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (i; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
crossDomain: false, // obviates need for sameOrigin test
beforeSend: function (xhr, settings) {
if (!csrfSafeMethod(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
В вопросе вы связаны, кто-то изменили его во время 'onLinkedInLoad' функции. Вы пробовали это? Отправьте код, который вы пробовали. –
Ты имеешь в виду этот? Я пробовал это, но кнопка не отображалась. –
Я сделал это, спасибо Ангел Политис! –