nkhanna24 Posted February 6, 2013 Share Posted February 6, 2013 public function actionFblogin() { $facebook = new Facebook(Yii::app()->params['fb']['config']); //$session = $facebook->getSession(); $user = $facebook->getUser(); $me = null; // Session based API call. if ($user) { $fb_uid = $facebook->getUser(); if (Yii::app()->user->id) { $user = User::model()->find('fb_uid=?', array($fb_uid)); if ($user === NULL) { Yii::app()->user->setState('fb_uid', $fb_uid); $this->redirect($this->createAbsoluteUrl('profile/settings', array('fbconnect' => 1))); Yii::app()->end(); } else { $this->redirect($this->createAbsoluteUrl('profile/settings', array('fbconnect' => 2))); Yii::app()->end(); } } else { $user = User::model()->find('fb_uid=?', array($fb_uid)); if($user->lastLogin==0) $firstTime=1; $_identity = new FbUserIdentity($fb_uid); $_identity->authenticate(); if ($_identity->errorCode === FbUserIdentity::ERROR_NONE) { $duration = 3600 * 24 * 30; // $this->rememberMe ? 3600*24*30 : 0; // 30 days Yii::app()->user->login($_identity, $duration); if($firstTime==1) $this->redirect($this->createAbsoluteUrl('site/demo', array('name' => $user->firstName))); else $this->redirect(Yii::app()->user->returnUrl); return true; } else $this->redirect($this->createAbsoluteUrl('site/fbregister')); } } else { $this->redirect($facebook->getLoginUrl(array('req_perms' => Yii::app()->params['fb']['config']['perms'], 'return_url' => $this->createAbsoluteUrl('site/fblogin')))); } } hi i have this actionFblogin in my sitecontroller.php the problem is when i click the button an error occur and it doesnt redirect to my website ? can anybody help me??? Link to comment Share on other sites More sharing options...
Antonio Conte Posted February 6, 2013 Share Posted February 6, 2013 What's the error message? What debugging steps have you taken? You provide to little context for anyone to help you. 2 Link to comment Share on other sites More sharing options...
nkhanna24 Posted February 6, 2013 Author Share Posted February 6, 2013 there is no error as such.....when i click on button,it takes to the facebook page and this is url https://www.facebook.com/dialog/oauth?client_id=112891755455541&redirect_uri=http%3A%2F%2Flocalhost%2Fsite%2Ffblogin&state=0bfbe3f220a29d0a67e20e3d346c3efd&req_perms=email%2Cpublish_stream%2Cmanage_pages&return_url=http%3A%2F%2Flocalhost%2Fsite%2Ffblogin it displays error line ,so dont know what to do?? Link to comment Share on other sites More sharing options...
Antonio Conte Posted February 6, 2013 Share Posted February 6, 2013 I've looked at the Facebook PHP API a bit. Anyone can find it here if interested: https://developers.facebook.com/docs/reference/php/ A general problem is that you don't read that API. I doubt that's really the issue, but take getLoginUrl() as an example: From the API: getLoginUrl(): Get a URL that the user can click to login, authorize the app, and get redirected back to the app. Example: $params = array( 'scope' => 'read_stream, friends_likes', 'redirect_uri' => 'https://www.myapp.com/post_login_page');$loginUrl = $facebook->getLoginUrl($params); You don't give facebook any of the keys they require. No scope and no redirect_uri. Facebook provides some application code example here btw:- https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php Your main problem is that you redirect way to much. I don't really think you should do that at all considering the example usage above. 1 Link to comment Share on other sites More sharing options...
Recommended Posts