2013-04-15 3 views
0

Я использую фреймворк javascript SDK для регистрации и входа в систему на моем сайте. Login работает нормально.Почему данные пользователя не хранятся в mysql с использованием имени fb?

Однако я хочу хранить данные в mysql, но каждый раз, когда я получаю eror в консольном журнале, как «$ не определен». После нескольких часов попыток и поиска, я не могу понять,

  1. Что я здесь делаю неправильно ?.

  2. Могу ли я использовать этот же код для аутентификации приложения холста facebook.?

Я недавно научился использовать аутентификацию fb.Plz мне помочь.

<script type="text/javascript"> 
    var button; 
    var userInfo; 

    window.fbAsyncInit = function() { 
    FB.init({ appId:'abccccc', //change the appId to your appId 
    status:true, 
    cookie:true, 
    xfbml:true, 
    oauth:true}); 

showLoader(true); 

function updateButton(response) { 
    button = document.getElementById('fb-auth'); 
    userInfo = document.getElementById('user-info'); 

    if (response.authResponse) { 
     register(); 

     FB.api('/me?', function (info) { 
      login(response, info); 

     }); 


     button.onclick = function() { 
      FB.logout(function (response) { 
       logout(response); 
      }); 
     }; 

    } else { 
     //user is not connected to your app or logged out 
     button.innerHTML = 'Login'; 
     button.onclick = function() { 
      showLoader(true); 
      FB.login(function (response) { 
       if (response.authResponse) { 
        FB.api('/me', function (info) { 
         login(response, info); 
        }); 
       } else { 
        //user cancelled login or did not grant authorization 
        showLoader(false); 
       } 
      }, {scope:'email,user_birthday,status_update,publish_stream,user_about_me'}); 
     } 
    } 

} 

function register() { 

    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function (response) { 

     console.log('Good to see you, ' + response.name + '.' + ' Email: ' + response.email + ' Facebook ID: ' + response.id); 


    }); 
    $.post('send.php', { option:'fb_register', name:response.name, email:response.email}, function (data) { 
     alert('registerd') 
    }); 

} 

// run once with current status and whenever the status changes 
FB.getLoginStatus(updateButton); 
FB.Event.subscribe('auth.statusChange', updateButton); 
}; 
(function() { 
var e = document.createElement('script'); 
e.async = true; 
e.src = document.location.protocol 
     + '//connect.facebook.net/en_US/all.js'; 
document.getElementById('fb-root').appendChild(e); 
}()); 


function login(response, info) { 
if (response.authResponse) { 
    var accessToken = response.authResponse.accessToken; 

    userInfo.innerHTML = '<img src="https://graph.facebook.com/' + info.id + '/picture">' + info.name 
      + "<br /> Your Access Token: " + accessToken; 
    button.innerHTML = 'Logout'; 
    showLoader(false); 
    document.getElementById('other').style.display = "block"; 
    } 
    } 

function logout(response) { 
userInfo.innerHTML = ""; 
document.getElementById('debug').innerHTML = ""; 
document.getElementById('other').style.display = "none"; 
showLoader(false); 
} 

//stream publish method 
function streamPublish(name, description, hrefTitle, hrefLink, userPrompt) { 
showLoader(true); 
FB.ui(
     { 
      method:'stream.publish', 
      message:'', 
      attachment:{ 
       name:name, 
       caption:'', 
       description:(description), 
       href:hrefLink 
      }, 
      action_links:[ 
       { text:hrefTitle, href:hrefLink } 
      ], 
      user_prompt_message:userPrompt 
     }, 
     function (response) { 
      showLoader(false); 
     }); 

} 
function showStream() { 
FB.api('/me', function (response) { 
    //console.log(response.id); 
    streamPublish(response.name, 'I like the articles of Thinkdiff.net', 'hrefTitle', 'http://thinkdiff.net', "Share thinkdiff.net"); 
}); 
} 
</script> 

ответ

1

register Ваша функция вызывает функцию $.post, предположительно из JQuery. Если у вас нет ничего загруженного, который определяет $, он не будет определен, и поэтому вызов $.post не будет выполнен.

Я бы предложил загрузить jQuery, который предоставляет $.post.

+0

Вы имеете в виду, библиотека jquery не включена? – user1452376

+0

Это правильно. Вы можете включить '' в свой HTML, чтобы включить его. – michaelb958

 Смежные вопросы

  • Нет связанных вопросов^_^