php - Facebook connect with codeigniter redirect in loop after login -
i trying connect facebook using codeigniter. if connecting fist time,then can see permission popup after authorise permission getting multiple redirect loop error.
if logged in , authorised site why not getting uid.
i have give site url in facebook: http://mysite.com/
and redirect uri http://mysite.com/facebook/
i have added these files in library folder.
library/fb_connect.php library/facebook/facebook.php library/facebook/base_facebook.php library/facebook/fb_ca_chain_bundel.crt last 3 files in facebook folder facebook sdk files.
here code in fb_connect.php
<?php include(apppath.'libraries/facebook/facebook.php'); class fb_connect { function connect(){ $facebook = new facebook(array( 'appid' => 'xxxxxxx', 'secret' => 'xxxxxxxxxxxxxx', 'cookie' => true, )); //get user id $user=$facebook->getuser(); if(!$user){ $loginurl=$facebook->getloginurl(array( 'scope' => 'email,publish_stream,user_birthday,user_location', 'redirect_uri' => 'http://localhost/beta/facebook/', 'display'=> 'popup' )); redirect($loginurl')"; exit(); } else { $user_profile = $facebook->api('/me'); print_r($user_profile); } ?> and here controller code:
function facebook(){ $this->load->library('fb_connect'); $user_data=$this->fb_connect->connect(); }
there's few things;
1.you said "and redirect uri http://mysite.com/facebook/" - in code:
'redirect_uri' => 'http://localhost/beta/facebook/', should be:
'redirect_uri' => 'http://mysite.com/facebook/', 2.you said "i have give site url in facebook: http://mysite.com/" - need set return url in facebook api aswell - should "http://mysite.com/facebook"
3.you said redirect "http://mysite.com/facebook/" - have set route? because should "http://mysite.com/mycontroller/facebook/"
4.you have typo (if copy + paste):
redirect($loginurl')"; should be
redirect($loginurl);
Comments
Post a Comment