2016-04-10 22 views
0

Facebookに登録しようとしていますが、thisプラグインを使用しています。 Facebookのログインページにリダイレクトされますが、Facebookにログインすると、私のウェブサイトに戻ってきません。すべてのアプリのsercretsとAPIキーがCodeIgniter Facebookに登録

答えて

0

に設定されている

class UserController extends CI_Controller { 
    public function fbSignup() { 
    $this->load->library('fb'); 
    if (!$this->fb->is_connected()) { 

     redirect($this->fb->login_url(current_url())); 
    } 

    $fb_user = $this->fb->client->api('/me'); 
    echo "<pre>"; 
    print_r($fb_user); exit; 
    if (empty($fb_user)) { 
     $error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__; 
     $this->session->set_flashdata('register_error', $error); 
    } else { 
     $this->user->set_facebook_id($fb_user['id']); 
     $user = $this->user->get_by_facebook(); 
     if (!empty($user) && !empty($user->id) && is_numeric($user->id)) { 
      //TODO: Make things a bit more secure here 
      //Login & Redirect home 
      $this->_login($user->id, 'facebook'); 
      $this->load->view('users/redirect_home'); 
      return; 
     } 
    } 
} 

} 

コントローラは、あなたがそこJSライブラリを使用して、あなたは、単にJavaScriptライブラリを使用していることを行うことができます任意のCodeIgniterのプラグインを使用する必要があります `tを

01)このスクリプトは、CodeIgniter、CakePHP、Laravelなどの任意のフレームワークを使用できます。新しいフレームワークで作業を開始するときは、時間を無駄にする必要はありませんこのスクリプトを使用することを暗示します。

02)JSを使用すると、facebook.comページにリダイレクトされないポップアップウィンドウであなたのウェブサイト上のfacecbookのログインフォームを開くことができます。

スクリプト -

<html> 
<body> 
<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '717505658366417', // Set YOUR APP ID 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
    }); 

    }; 

    function Login() 
    { 

     FB.login(function(response) { 
      if (response.authResponse) 
      { 
       getUserInfo(); 
      } else 
      { 
      console.log('User cancelled login or did not fully authorize.'); 
      } 
     },{scope: 'email,user_photos,user_videos'}); 

    } 

    function getUserInfo() { 
     FB.api('/me', function(response) { 
     var str="<b>Name</b> : "+response.name+"<br>"; 
      str +="<b>Link: </b>"+response.link+"<br>"; 
      str +="<b>Gender:</b> "+response.gender+"<br>"; 
      str +="<b>id: </b>"+response.id+"<br>"; 
      str +="<b>Email:</b> "+response.email+"<br>"; 
      str +="<input type='button' value='Get Photo' onclick='getPhoto();'/>"; 
      str +="<input type='button' value='Logout' onclick='Logout();'/>"; 
      document.getElementById("status").innerHTML=str; 

    }); 
    } 
    function getPhoto() 
    { 
     FB.api('/me/picture?type=normal', function(response) { 

      var str="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>"; 
      document.getElementById("status").innerHTML+=str; 

    }); 

    } 
    function Logout() 
    { 
     FB.logout(function(){document.location.reload();}); 
    } 

    // Load the SDK asynchronously 
    (function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 

</script> 
<div align="center"> 
<h2>Facebook OAuth Javascript Demo</h2> 

<div id="message"> 
Logs:<br/> 
</div> 
</div> 
</body> 
</html> 
+0

おかげで、それは任意のものを返すのではなく、任意のエラーを取得 – baig772

+0

それ 'sのそれがログインするが、私はお返しに任意のものを見ることができませんか? –

関連する問題