php - 如何使用 codeigniter 登录 facebook

标签 php facebook codeigniter session

1.Facebook登录的基本步骤是什么,当用户使用Facebook登录时,如何从Facebook访问其信息。登录成功后如何重定向。

2.当用户第一次登录时,我们会获取该用户的信息,下次登录的过程是什么,即当用户第一次登录时,我们有该用户的信息,那么下次登录的过程是什么。

最佳答案

您好,您必须使用基本用户身份验证。

我使用本教程在我的应用程序中使用 Facebook JDK 和 Codeigniter: http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/

但我建议您使用Javascript SDK进行身份验证。

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
  appId      : '[ID]', // App ID
  channelUrl : '[URL]', // Channel File
  status     : true, // check login status
  cookie     : true, // enable cookies to allow the server to access the session
  xfbml      : true  // parse XFBML
});  
var login = false;
 FB.getLoginStatus(function(response) {
          if (response.status === 'connected') {
              console.log('connected');
              login=true;
                // the user is logged in and connected to your
                // app, and response.authResponse supplies
                // the user's ID, a valid access token, a signed
                // request, and the time the access token 
                // and signed request each expire
                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;
          }
          else{
              FB.login(function(response) {
               if (response.authResponse) {
                 console.log('Welcome!  Fetching your information.... ');
                 FB.api('/me', function(response) {
                   console.log('Good to see you, ' + response.name + '.');
                   if(login===false)
                   {
                       window.open("[APPLINKONFACEBOOK]", "_top");
                   }
                   //window.location.href=window.location.href;
                   //FB.logout(function(response) {
                     //console.log('Logged out.');
                   //});
                 });
               } else {
                 console.log('User cancelled login or did not fully authorize.');
               }    
             }, {scope: 'email'});
          }});

// Additional initialization code here
};
 (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);  
  }());
  // Load the SDK Asynchronously
 (function(d){
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all.js";
 d.getElementsByTagName('head')[0].appendChild(js);
 }(document));

 </script>

关于php - 如何使用 codeigniter 登录 facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9734817/

相关文章:

php - 获取搜索表单的结果 - MySQL PHP

php - 删除 WooCommerce 结帐字段值

javascript - 使 Facebook 页面插件响应(到处搜索,找不到解决方案)

php - Facebook 架构和数据库 ID 的起始量为数万亿

php - 如何获取特定日期范围内的记录

mysql - 即使没有结果,也从 Mysql 数据库获取按月计数

php回显不显示

php - .htaccess 中的基本 URL

javascript - Facebook Open Graph - 'Like Button' - 'Like' 显示的 Conceal 内容

php - 分阶段形式和 "going back"(在浏览器中单击 "back")