Search code examples
facebookyii2cross-site

I facing error on facebook sdk login using yii2


Actually I'm trying to get user Long lived access token and user id with facebook sdk plugin in yii2. But problem I facing is that when we click on facebook login button it will go to the facebook page correctlly and login successfully, but when it came to return website url it show some error Like Cross-site state param is missing or When i remove this error than it will show me

Facebook\Exceptions\FacebookSDKException

Connection timed out after 10001 milliseconds

exception 'Facebook\Exceptions\FacebookSDKException' with message 'Cross-site request forgery validation failed. Required param "state" missing from persistent data.' in /home/host4lev/public_html/social_post/vendor/facebook/php-sdk-v4/src/Facebook/Helpers/FacebookRedirectLoginHelper.php:244 Stack trace: /home/host4lev/public_html/social_post/vendor/facebook/php-sdk-v4/src/Facebook/Helpers/FacebookRedirectLoginHelper.php(221): Facebook\Helpers\FacebookRedirectLoginHelper->validateCsrf() /home/host4lev/public_html/social_post/frontend/controllers/SiteController.php(510): Facebook\Helpers\FacebookRedirectLoginHelper->getAccessToken() [internal function]: frontend\controllers\SiteController->actionChecklogin() /home/host4lev/public_html/social_post/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array) /home/host4lev/public_html/social_post/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\InlineAction->runWithParams(Array) /home/host4lev/public_html/social_post/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('checklogin', Array) /home/host4lev/public_html/social_post/vendor/yiisoft/yii2/web/Application.php(100): yii\base\Module->runAction('site/checklogin', Array) /home/host4lev/public_html/social_post/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request)) /home/host4lev/public_html/social_post/frontend/web/index.php(17): yii\base\Application->run() {main}

I tried lot's of solution but doesn't make any effect so please give some suggesion on that.

And this same code running perfectly on localhost but when do it to live server it come with error.


Solution

  • finally i got an answer for my question.Actually problem is not in my code when i checked my cpanel configuration than i find that my port 80 is blocked so it want accepting the response of facebook api when fix(unblock port 80) that all happen good for me. Thank you so much for your all suggetions