facebook SDK登录错误跨站点请求伪造验证失败。必需的参数"州"失踪

时间:2016-02-04 01:45:53

标签: php facebook magento login

我在loacted here使用此sdk http://example.com/module/index/callback函数尝试为magento创建facebook登录信息但是我一直收到以下错误。

  

跨站点请求伪造验证失败。必需的参数"州"丢失。

这是我在回调中使用的代码,其中生成错误

 public function callbackAction()
    {       
          $fb = Mage::helper('mymodule')->getFacebookApp();
          $helper = $fb->getRedirectLoginHelper();       

        try {

            $accessToken = $helper->getAccessToken();
            if (! isset($accessToken)) {
                if ($helper->getError()) {
                    Mage::helper('mymodule')->log($helper->getError());
                    Mage::getSingleton('customer/session')->addError($helper->getErrorReason());
                    $this->_redirect('customer/account');
                } else {
                    Mage::getSingleton('customer/session')->addError('Bad request');
                    $this->_redirect('customer/account');
                }
            } else {
                $_access_token = (string) $accessToken;
                $fb->setDefaultAccessToken($_access_token);
                $response = $fb->get('/me?locale=en_US&fields=name,email,first_name,last_name,middle_name');
                $userNode = $response->getGraphUser();
                try {
                    if(!Mage::helper('mymodule')->checkExistCustomer($userNode['email'])){
                        Mage::helper('mymodule')->createCustomer($userNode);
                    }
                } catch (Exception $ex){
                    Mage::getSingleton('customer/session')->addError("Login failed" . $ex->getMessage());
                    $this->_redirect('customer/account');
                }
                Mage::helper('mymodule')->forceCustomerLogin($userNode['email']);
                Mage::getSingleton('customer/session')->addSuccess("You have just logged in successfully using facebook");
                $this->_redirect('customer/account');
            }

        } catch(Facebook\Exceptions\FacebookResponseException $e) {
            // When Graph returns an error
            Mage::helper('mymodule')->log('Graph returned an error: ' . $e->getMessage());
            Mage::getSingleton('customer/session')->addError("Login failed: " . $ex->getMessage());
            $this->_redirect('customer/account');
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
            // When validation fails or other local issues
            echo $e->getMessage();
            Mage::helper('mymodule')->log('Facebook SDK returned an error: ' . $e->getMessage());
            Mage::getSingleton('customer/session')->addError("Login failed:" . $e->getMessage());
            $this->_redirect('customer/account');
        }
    }

这是我用来执行功能的链接

<a target="_self" href="https://www.facebook.com/v2.4/dialog/oauth?client_id={my_app_id}&amp;state=0effd41e556da131b0dbfe381b3e7a79&amp;response_type=code&amp;sdk=php-sdk-5.0.0&amp;redirect_uri=http://example.com/mymodule/index/callback/;scope=email">log into facebook</a>

如何解决此错误?

0 个答案:

没有答案