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 FacebookFacebook([
'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 FacebookFacebook([
'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 (FacebookExceptionsFacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (FacebookExceptionsFacebookSDKException $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() . "
";
echo "Error Code: " . $helper->getErrorCode() . "
";
echo "Error Reason: " . $helper->getErrorReason() . "
";
echo "Error Description: " . $helper->getErrorDescription() . "
";
} 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 curlCurl();
$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...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…