My problem is I get Instagram id and username, but I will need full name, profile image, email etc. I get like this Array:
( [id] => 123456 [username] => abc123)
$code = $this->getRequest()->getParam('code');
$instaAppId = $this->modelDataProvider->getAppApiKey(self::SOCIAL_TYPE);
$instaAppSecret = $this->modelDataProvider->getAppApiSecret(self::SOCIAL_TYPE);
$instaRedirectUrl = $this->modelDataProvider->getRedirectCallbackUrls(self::SOCIAL_TYPE);
$setAccessToken = $this->getAccessTokenValue($instaAppId, $instaRedirectUrl, $instaAppSecret, $code);
$AccessToken = $setAccessToken['access_token'];
$instauserinfo = $this->getInstagramUserProfile($AccessToken);
print_r($instauserinfo);
protected function getAccessTokenValue($instaAppId, $instaRedirectUrl, $instaAppSecret, $code)
{
$token = [];
try {
$request = 'client_id='. $instaAppId . '&redirect_uri=' . $instaRedirectUrl . '&client_secret=' . $instaAppSecret . '&code='. $code . '&grant_type=authorization_code';
$this->curlClient->setOptions([
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_TIMEOUT => 60,
CURLOPT_POSTFIELDS => $request,
CURLOPT_HEADER => false,
CURLOPT_VERBOSE => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => [
'Content-Type: application/x-www-form-urlencoded',
]
]);
$this->curlClient->get('https://api.instagram.com/oauth/access_token');
$token = $this->json->unserialize($this->curlClient->getBody());
} catch (\Exception $exception) {
$token['errorMessage'] = $exception->getMessage();
}
return $token;
}
protected function getInstagramUserProfile($AccessToken)
{
$instaprofileid = [];
try {
$this->curlClient->setOptions([
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_TIMEOUT => 60,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $AccessToken,
]
]);
$this->curlClient->get('https://graph.instagram.com/me/?fields=id,name,username,profile_picture_url&access_token='. $AccessToken);
$instaprofileid = $this->json->unserialize($this->curlClient->getBody());
} catch (\Exception $exception) {
$this->getResponse()->setBody($exception->getMessage());
}
return $instaprofileid;
}
I get only id and username. I need all info from instagram .
I try to social login plugin.