Hi same error i faced in yii2, i solved like below..,
this code is in view, also no need to use namespace for sdk,
$fb = new \Facebook\Facebook([ 'app_id' => 'xxxxxxxxxxxxxxxxxxxx', 'app_secret' => 'xxxxxxxxxxxxxxxxxxxxxxx', 'default_graph_version' => 'v3.0', 'display' => 'popup', ]); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email','manage_pages','instagram_basic','instagram_manage_insights']; // Optional permissions $loginUrl = $helper->getLoginUrl('https://xxxxxxxxxxxxxxxxxxxx/site/contact/', $permissions);
******login button
<a class="btn btn-sm-connect instagram" href="<?= $loginUrl?>" onClick="MyWindow=window.open('<?= $loginUrl?>','MyWindow',width=600,height=300); return false;>
MyWindow=window.open( --> this for open in a pop up model )
*** controller action code
public function actionContact() { $fb = new \Facebook\Facebook([ 'app_id' => 'xxxxxxxxxxxxxxxxxxxx', 'app_secret' => 'xxxxxxxxxxxxxxxxxxxx', 'default_graph_version' => 'v3.0', ]); $helper = $fb->getRedirectLoginHelper(); // echo "<pre>"; // print_r($helper); exit; 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; } if (!isset($accessToken)) { if ($helper->getError()) { header('HTTP/1.0 401 Unauthorized'); echo "Error: " . $helper->getError() . "\n"; echo "Error Code: " . $helper->getErrorCode() . "\n"; echo "Error Reason: " . $helper->getErrorReason() . "\n"; echo "Error Description: " . $helper->getErrorDescription() . "\n"; } else { header('HTTP/1.0 400 Bad Request'); echo 'Bad request'; } exit; } // // Logged in // echo '<h3>Access Token</h3>'; // var_dump($accessToken->getValue()); $token = $accessToken->getValue(); // echo $token; //curl request to fb $pageModel = new Pages(); $followersModel = new Followers(); $curl = new curl\Curl(); $response = $curl->setGetParams([ // 'fields' => 'fan_count,name', 'access_token' => $token ]) ->get('https://graph.facebook.com/v3.0/me/accounts'); $pages = json_decode($response); $pagesList = json_decode(json_encode($pages), True); $serviceProvider = 'instagram';
.... remaining u can take care of it...