Facebook SDK返回错误:Stream在facebook SDK5 php CodeIgniter 3中返回空响应

时间:2019-01-06 03:46:12

标签: php facebook codeigniter login facebook-php-sdk

上周,我在CODEIGNITER 3上通过composer安装了facebook SDK,它可以正常工作并返回名称电子邮件和令牌,直到今天,当我尝试登录时页面加载1分钟,然后出现空白页面,并出现以下错误: >

空错误 Facebook SDK返回错误:

并返回此URI https://www.mywebsite.com/en/fbcallback?code=AQCCasdfSAD35L-3iABFbT5zntYQ4jJHVcko9ekG-6k-jn5aERodXoasdf7jHWEgSxxqze_K-nyAYSmcASDFaskde6wPasdfD8WHBEFUEO5gNpgLU0RJqnvVGCdYKNfT2Qm5U1pcWCvVE_YkJ6sQyUL0RrcONrqMbb7bpPv0KDUQjaO_XMAwvKEo2Jasdf31PCjxoHBGoogupX8VF5Gx6WaT4b7ZlsYkPhbQPTCdJaWrzwvfJ1So27Wsdt1Ub9WPUO07io3vxmX-P-rmzsxnk3qDSKCPJX9ks0eBtNwXA-83&state=8cbe21da648d832fcd2b34aceb8dfe62#=

我在控制器中使用2个操作进行登录:

function fblogin(){

        $fb = new Facebook\Facebook([
              'app_id' => 'my app id ',
              'app_secret' => 'my app secret',
              'default_graph_version' => 'v3.2',
            ]);

       $helper = $fb->getRedirectLoginHelper();
       $permissions = ['email'];
    // For more permissions like user location etc you need to send your application for review
       $loginUrl = $helper->getLoginUrl('https://www.example.com/en/fbcallback', $permissions);
       header("location: ".$loginUrl);
    }

此应返回令牌信息的位置:

function fbcallback(){

      $fb = new Facebook\Facebook([
          'app_id' => 'myid',
              'app_secret' => 'myscretapp',
          'default_graph_version' => 'v3.2',
        ]);

        $helper = $fb->getRedirectLoginHelper();

        try {

            $accessToken = $helper->getAccessToken();

        }catch(Facebook\Exceptions\FacebookResponseException $e) {
          // When Graph returns an error
          echo 'Graph returned an error: ' . $e->getMessage();
          exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
          // When validation fails or other local issues
          echo 'Facebook SDK returned an error: ' . $e->getMessage();
          exit;
        }


        try {
          // Get the Facebook\GraphNodes\GraphUser object for the current user.
          // If you provided a 'default_access_token', the '{access-token}' is optional.
          $response = $fb->get('/me?fields=id,name,email,first_name,last_name',$accessToken);
         // print_r($response);
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
          // When Graph returns an error
          echo 'ERROR: Graph ' . $e->getMessage();
          exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
          // When validation fails or other local issues
          echo 'ERROR: validation fails ' . $e->getMessage();
          exit;
        }

        // User Information Retrival begins................................................
        $me = $response->getGraphUser();

        echo "First Name: ".$me->getProperty('first_name')."<br>";
        echo "Last Name: ".$me->getProperty('last_name')."<br>";
        echo "Email: ".$me->getProperty('email')."<br>";
        echo "Facebook ID: <a href='https://www.facebook.com/".$me->getProperty('id')."' target='_blank'>".$me->getProperty('id')."</a>"."<br>";
        $profileid = $me->getProperty('id');
        echo "</br><img src='//graph.facebook.com/$profileid/picture?type=large'> ";
        echo "</br></br>Access Token : </br>".$accessToken;


    }

2年前问了同样的问题,但没有答案: link

1 个答案:

答案 0 :(得分:0)

我的问题出在服务器端:

此功能允许您指定某些IP或IP范围,您可以将其打开传出连接。

只需转到服务器,然后检查它是否阻止传出连接即可。... 我将其添加到白名单中并正常工作! ...希望可以节省您的时间。